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 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

scripts.js
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:

alert(message);

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