Appending variable to strings

dont know what to do in this

Your code so far


// Change code below this line

var someAdjective ="worth while a";
var myStr = "Learning to code is ";
ourStr += someAdjective;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Appending Variables to Strings

Link to the challenge:

ourStr doesn’t exist in this code, why are you using it here?

It is showing in example of the activity.

You’re not supposed to copy EXACTLY what’s on the example. It’s called an example for a reason. There is always an instruction to use.

1 Like

but it doesn’t exist in the code editor

the two variables defined there are someAdjective and myStr

the example is showing the feature that is this challenge topic with different variables. You can’t copy exactly the example, it wouldn’t work

1 Like

OK. Now I understand can u pls tell me about how to use the += operator

Now I got it. Thanks for recognising it to me.

You used the += in your original code above. Is there something confusing you about how you used it above other than the fact that you are referencing the non-existent ourStr variable?

  • The += operator is just a shortcut for variable = variable + sum. Here’s an example:
var x = 1;
var y = 2;
x += y; //this will output 3
//it is the same thing as
x = x + y;//this will also output3

//You can also use it to add strings as what the challenge is basically
//asking you to do

Thanks for explaining well. Now I got what the exerxise is asking. :grinning: