Help with JavaScript challenge

Hello all!

So I’m attempting a JavaScript challenge on this site that requires me “to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb.”

To provide some context, this was the original code that was given to me before I attempted this challenge:

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

// Your code above this line
  return result;
}

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

Plus, I would “also need to use additional strings, which will not change, and must be in between all of the provided words. The output should be a complete sentence.”

To successfully complete this challenge, I must satisfy the following conditions:

  • 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).

Now, here are the variables and strings I created in an attempted to complete the challenge:

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";
  // Your code below this line
  var modifier = "The";
  var anotherAdverb = "very";
  var prepositionalPhrase = "to the ball";
  var conjunction = "and";
  var anotherAdjective = "fast";
  var actionVerb = "turned around and";
  var wordBlanks = modifier + myAdjective + conjunction + anotherAdjective + myNoun + actionVerb + myVerb + prepositionalPhrase + anotherAdverb + myAdverb;
  result = wordBlanks;
  // Your code above this line
  return result;
}

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

When I hit enter, this is the result I get:

Thebigandfastdogturned around andranto the ballveryquickly.

I was able to meet the first condition, but I’m still struggling to meet the last two. My initial thought was that because there isn’t spacing between all the words, it is not being read as a complete sentence and that’s why I can’t satisfy the last two conditions of this challenge.

But then I remembered a previous challenge that I did that was similar to this. I was able to successfully complete that challenge even there wasn’t spacing between all the words in the sentence I created. So if spacing isn’t the reason why I can’t meet the last two conditions of this challenge, then I am not sure what is.

Please let me know if there is any additional information you would like for me to provide in order to better understand my problem. Thanks to all who responded to this post. Your input is greatly appreciated!

  • Abhi

Your intial thought seems to be correct. If you take a look at the quote below (from both your 2nd and 3rd requirements), it specifically asks for it to be separated by something other than a word. A space should do it.

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

Ah, yes. It’s always one of those little things that throws everything off!

Thanks for pointing that out, though. Much appreciated!

This is my solution:::

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
// Your code below this line

var result = " ";
result = “My” + " " + myNoun + " " + “is” + " " + myAdjective + " " + “and” + " " + myVerb + " " + myAdverb + “.”;
// Your code above this line
return result;
}

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