Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Why is this not working?

i am doing another JavaScript Basics course and wondering why this is not working.

var userName = "Chris";

var score = 100;

score++;

score++;

score++;

var displayScore = "<h1>" userName + "'s score is " + score + " points</h1>";

document.write(displayScore);

if i remove the h1 tags it works. would be cool if somebody could explain me this. Thanks guys

2 Answers

Hey there Lei,

you only made one tiny mistake. You have to add a "+" between your opening h1 tag and the userName variable to concatenate it correctly.

Like so:

var displayScore = "<h1>" + userName + "'s score is " + score + " points</h1>";

I hope that helps! :)

Thanks mate. I was going nuts here already. Cheers

No problem, glad I could help! :)