Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Quickstart Data Types and Variables Creating Variables

Chany Ventura
Chany Ventura
2,209 Points

var myName = "Chany" var myAge = 31 var message = "Chany + is + 31" alert("Chany" + "is" + "31"); What's wrong?

It says I have to leave an space before and after the word "is" I DONT GET IT

var myName = "Chany"
var myAge = 31
var message = "Chany + is + 31"
alert("Chany" +  "is"  + "31");

1 Answer

Stanley Thijssen
Stanley Thijssen
22,831 Points

Hi there Chany, first of all everything you put in between double quotes ("") will be a string and the variable assigned to it will be exactly equal to that string. So for example your message variable now has the value:

"Chany + is + 31"

It would be better practice to reuse the variables you assigned before that, so:

var message = myName + " is " + myAge;

As you can see here I reuse the variable you defined earlier, and also used the string " is " with a space prepended and appended to it. This makes sure you get back a value like:

"Chany is 31"

After you have defined your message variable you can simply pass it to the alert() function like so:


I hope this helps you out and makes you understand better how to combine variables with strings (concatenation).