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 JavaScript Basics (Retired) Making Decisions with Conditional Statements Build a Random Number Guessing Game

YI JIANG
YI JIANG
3,424 Points

The number was ' + randomNumber + '

I don't understand this part why ' put there? not here 'randomNumber'?

1 Answer

Rune Andreas Nielsen
Rune Andreas Nielsen
5,354 Points

The reason that you don't use ' between + and randomNumber, is that if u do that, the browser won't know itΒ΄s a variable, it would think it is a string.

When using the + symbol, the browser knows itΒ΄s job is to concatenate the variable with the string.

So lets say that you would write code like this:

var randomNumber = 10;
alert('The number was ' + 'randomNumber' + '.')

Then the output would be "The number was randomNumber."

Using the syntax the video shows:

var randomNumber = 10;
alert('The number was ' + randomNumber + '.')

The output will be "The number was 10."