Word Blanks and understanding concatenation operators in JS

here is my code:

  myNoun = "dog";
  myAdjective = "big";
  myVerb = "ran";
  myAdverb = "quickly";
  WordBlanks = "MyNoun + MyAdjective + myVerb + myAdverb";

I took a look at the solution, which is similar to mine but does a concatenation operator at the end with the blank string at the top, and also uses the += operator instead of +. I don’t completely understand these changes, or why my code fails.

Thanks for any help,

–Sam

the above preview is actually a link to the exercise. it’s exercise 151.

+= means your adding on to the variable but also changing it to equal the two strings
For example if I did

function exampleFunction(number) {
   number + 12;
   return number + 10;
}
exampleFunction(10)

It would return 20 but if I used a += operator

function exampleFunction(number) {
   number += 12;
   return number += 10;
}
exampleFunction(10)

It would add the number to the variable and change the variable to the new number twice so it would now equal 32

In other words a “=” changes the variable and “+” adds to it but doesn’t change it so a “+=” adds to it and changes it

P.S. I am 14 so correct me if I am wrong.

You don’t need to set up any new variables (just use result). All of the variables should be passed in using the arguments of the function.

Your function should be something like this:

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) { // These are your variables
// They're set as whatever arguments you pass in to the function
// Don't assign new variables with the same name within the function,
// or you'll break it.
  var result = "";
  
  /* Here, you build up `result` into a sentence.
  You can either reassign `result` as the full sentence
  using `+` to concatenate, or build it up step by 
  step using `+=` */

  return result;
}

Examples of + vs +=

var a = '';
var b = '';

var c = ',';
var d = '!';

a = 'Hello' + c + ' World' + d; // reassigns `a`

b += 'Hello';
b += c;
b += ' World';
b += d; // building up `b` step-by-step

a; // "Hello, World!"
b; // "Hello, World!"

a === b; // true