Word Blanks help?

Word Blanks help?
0

Tell us what’s happening:

Your code so far


function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  // Your code below this line
  var result = "";
myNoun ="dog";
myAdjective ="big";
myVerb ="ran";
myAdverb ="quickly";
  // Your code above this line
  return result += "My "+myAdjective+" "+myNoun+" "+myVerb+" very "+myAdverb+".";
// Change the words here to test your function
wordBlanks("cat", "little ",  "hit ", "slowly");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/word-blanks

Hello @rjplus
Here is one of the acceptable solution :

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

    // Your code above this line
  return result;
}

I don’t need to rewrite the variables inside the function again. There already exist in the function declaration
So the only this you must do is to create the sentence with spaces and nothing extra.

Your problem is that you did not close your function definition with a curly brace }.

  return result += "My "+myAdjective+" "+myNoun+" "+myVerb+" very "+myAdverb+".";
} // <-- MISSING }

wordBlanks("cat", "little ",  "hit ", "slowly");

Also, to build on @dhmm solution, you could do the following:

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  return `My ${myAdjective} ${myNoun} ${myVerb} very ${myAdverb}`;
}

wordBlanks("cat", "little ",  "hit ", "slowly");

This solution uses JavaScript ES6 template strings. I prefer to use template strings in these cases because it makes your code look much cleaner and easier for other developers to read. You can use FreeCodeCamp to learn more and practice using template strings here. You can read more on the MDN docs here.

1 Like