Add Word Blanks Using JavaScript

In this challenge, we provide you with a noun, a verb, an adjective and an adverb. You need to form a complete sentence using words of your choice, along with the words we provide.

You will need to use the string concatenation operator + to build a new string, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb. You will then assign the formed string to the result variable.

this is what they provide:
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
// Your code below this line
var result = “”;

// Your code above this line
return result;
}

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

This is what criteria i need to meet:
wordBlanks("","","","") should return a string.
wordBlanks(“dog”, “big”, “ran”, “quickly”) should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
wordBlanks(“cat”, “little”, “hit”, “slowly”) should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).

I tried doing what they previously taught me, but it didnt work, please help

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

You said you tried to write some code to solve the challenge, but the code above is just the original code the challenge starts with. Please copy/paste the latest code you have tried which fails the tests, so we can give you some advice.

I did this:
var result = “The " + " myAdjective” + " myNoun" + " myVerb" + " myAdverb" + " to me.";
Which did not work and I did this:
var myNoun = “dog”;
var myAdjective = “big”;
var myVerb = “ran”;
var myAdverb = “quickly”;
var result = “The " + " myAdjective” + " myNoun" + " myVerb" + " myAdverb" + " to me.";

I think what you are not understanding is that myNoun, myAdjective, myVerb, and myAdverb are variables to be used inside the function.

var result = “The " + " myAdjective” + " myNoun" + " myVerb" + " myAdverb" + " to me.";

Your first approach was closer to what you want to do, but to use a variable, you would not surround it with quotes like you are doing . Try again and see if you can make it work.

Thank you, I got that sentence worked out, I just needed to remove the quotes. The other aspect is also really confusing. Is it also telling me to do something with these words?
wordBlanks(“cat”, “little”, “hit”, “slowly”) should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).

Tell us what’s happening:
I cannot figure out the second part of this.

Your code so far
var myNoun = "dog ";
var myAdjective = "big ";
var myVerb = "ran ";
var myAdverb = "quickly ";
var result = "The " + myAdjective + myNoun + myVerb + myAdverb + “to me.”;
This is correct for the first part
the second part is
wordBlanks(“cat”, “little”, “hit”, “slowly”) should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
This is what I am given
// Change the words here to test your function
wordBlanks(“cat”, “little”, “hit”, “slowly”);


function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  // Your code below this line
  var myNoun = "dog ";
  var myAdjective = "big ";
  var myVerb = "ran ";
 var myAdverb = "quickly ";
  var result = "The " + myAdjective + myNoun + myVerb + myAdverb + "to me.";

  // Your code above this line
  return result;
}

// Change the words here to test your function
 wordBlanks("cat", "little", "hit", "slowly");

Your browser information:

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

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

You’re not supposed to make these variables, as they will override the input to the wordBlanks function. So regardless of your input, it will always output 'The big dog ran quickly to me.'

1 Like

Hi Sarah1…did you ever find a solution for the 2nd part? I have the same problem. It works with dog, big, ran and quickly, but I don’t know how to do the second part with cat, little, hit and slowly. Please help :disappointed_relieved:

What is your code? Just use the parameters of the function without changing them, the last poster before you said it correctly

But if you can’t solve it with this, use the “Ask for help” button inside the challenge to create your own post

1 Like

Thanks ieahleen! So simple, but thanks a lot for your patience with me :slight_smile: