Word Blanks - Not Understanding What Is Being Asked

Tell us what’s happening:
I’ve been stuck on this challenge for a couple days. The instructions are unclear. When I run a test I don’t understand what this means.

“// running test
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).
// tests completed”

Your code so far


function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  // Your code below this line
  var result = "My" + myNoun + "took a" + myAdjective + "shit so" + myAdverb + "it" + myVerb + "away.";

  // Your code above this line
  return result;
}

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

Your browser information:

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

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

The whole point of this exercise is to use the values passed into the wordBlanks function and then return a complete sentence. You are using the values passed into the function, but you are not returning a sentence. See below for the string you are returning with wordBlanks(“dog”, “big”, “ran”, “quickly”). You need some spaces and punctuation (non-word characters) to create a proper sentence.

‘Mydogtook abigshit soquicklyitranaway.’

Ok, but where does “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).” come into play here?

The first argument passed into wordBlanks is the value “cat”. This corresponds to the myNoun parameter defined by the function. So when you used myNoun inside the function, it is really just the value “cat”. The same goes for the 2nd, 3rd, and 4th function arguments.

Inside your function, you just need to add some spaces (before and/or after) the extra words you have chosen to use for your sentence, so the spaces become part of the string to create an actual sentence (which has spaces between the words).

The return value from word blanks should be a sentence, with the words [given as arguments] in order, separated by spaces (and any other words or punctuation you want to put between them)

Hi I’m not sure if this thread is still open, but I’m having the same problem here, it keeps asking me for nonword characters, which I’m assuming are spaces. However I have put spaces within my quotations and I have tried it with and without spaces between my plus signs, all to no avail.

What am I missing here?

Thanks in advance

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  // Your code below this line
  var result = "My " + myAdjective + "fluffy " + myNoun + "heard a noise " + myVerb + "and barked " + myAdverb + "like a little girl.";

  // Your code above this line
  return result;
}

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

Hi All,

I found a solution that works - the only spaces should be inside the quotations. No blank space outside of them. My solution, which worked:

var result = “The “+myNoun+” was “+myAdjective+” and “+myVerb+” very “+myAdverb+”.”;

2 Likes

I got it! you just have to add spaces before and after you word or at least that’s how I got my answer right.

Just got to this challenge and I have to agree with the OP that it’s very confusingly worded if you’re new to JS (Exactly the people who the course is aimed at).

If it only asked you to play around with the dog, big, ran, quickly string then it might not be so bad, but because of the addition of the cat, little, hit, slowly string it makes it seem like you need to make wholesale changes to the code.

Because the code (at this point) does nothing tangible it’s very difficult to conceptualise and process what’s going on and the addition of the cat string, in my opinion, adds an unneccesary layer of complexity.

The other test is to verify that you didn’t hardwrote the words in your string. It is the only way to verify it that still gives you freedom to play with the string as you want.

It is a thing started later, but it could be a good place to meet console.log() for debugging purposes.
Also, in the challenge description there is clearly written to add the spaces.
I imagine the example which doesn’t include spaces may be misleading…

1 Like

Thanks for the explanation of why it’s structured like it is. My confusion came not so much with the answer but the construction of the question, as I feel like it leads you into thinking that the question is more complex than it is instead of it actually being just a case of typing a string.

You’ll also see that the cat string is only referred to in the ‘necessary’ list at the bottom of the page, so given the body text of the question and the example code only refers to the dog it leads you to scratch your head about the cat, as the bottom of the page is the first mention of it.

I’m well past it now, but it was interesting to see how many other threads there were about this question and that I’m glad I wasn’t the only one who found it a bit oblique :smiley:

Would have been great if the use of “function” had been explained, and passing values into it. This is a free site, so I can’t complain, but if anybody updates these lessons, a quick blurb about THAT would be more helpful than explaining what MadLibs is.

1 Like