Basic JavaScript: Word Blanks excercise

Basic JavaScript: Word Blanks excercise
0

#1

Okay guys I have noticed something,

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  // Your code below this line
  var result = "";
  result+= "My "+myAdjective+" "+myNoun+" "+myVerb+" very "+myAdverb+".";

  // Your code above this line
  return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");

This is the answer for Word Blanks exercise but I cannot get the reason why we used += concentrating symbol?


#2

That’s one answer to the challenge, but it’s not the cleanest one. You’re right that concatenating like that really isn’t necessary.


#3

Are there other answers for this that you know?


#4

There are any number of variations on this. The idea is to construct your own sentence.


#5

You could do all of this in a single line of code if you just assign the string you created to result in the first line instead of initializing result to a blank string. That way, you could avoid using the += operator.