Word Blanks i need help please, i am a beginner, i`ve been trying on this code for the past one hour, and can`t seem to figure out why it won`t run

Tell us what’s happening:

Your code so far


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

 result = "The " +myNoun+ "ate " +myAdjective+ "and " +myVerb+ "away " +myAdverb;
  // 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 (Windows NT 6.1; WOW64; rv:65.0) Gecko/20100101 Firefox/65.0.

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

Be mindful of the spaces in your sentence, for example:

result = "The " +myNoun+ "ate "

Once run will result in:

"The dogate "

since there’s no space between myNoun and "ate ".

Hope it helps :+1:

1 Like

oh thanks a lot for the reply. i have just tried running the code again, this time with all the spaces included, just like you`ve told me yet the program tells me this;

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)

i do understand what next to do as i have tried basically all i have been told to in the ‘hints’.
:cry:

easy way

just add + ' ' to each of your arguments
eg. myNoun = myNoun + ' '

fancy way

function foo(some, word) {
  // loop though each argument and add a space to the end of it
  Object.keys(arguments).map(i => (arguments[i] = arguments[i] + " "));
  let result = "this " + some + "is " + word + "good";
  return result;
}
foo("cake", "really");

References
Object.keys()
Array.map()
arguments

1 Like

Can you elaborate more on your issue, I don’t quite understand it

1 Like

okay. first all, thanks for the reply
the problem i have been having for some hours now has been on the Basic JavaScript challenge, on Word Blanks precisely. I actually am a beginner. I posted the my typed code along with this topic; as i have followed all the instructions given to me on the hints to the best of my understanding and am still not getting my desired result on the challenge. This is what my code looks like:

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = “”;
// Your code below this line
myNoun = “dog”
myAdjective = “big”
myVerb = “ran”
myAdverb = “quickly”
result += “The” +myNoun + “ate” +myAdjective + “and” +myVerb + myAdverb;
// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks(“The” + “dog” + “ate” + “big” + “and” + “ran” + “away”+ “quickly”);

result += "my " + myNoun + " is very " + myAdjective + " and can " + myVerb + " very " + myAdverb;
I think the spaces might be a little confusing but just be careful next time, let me know if you have any more question.
p.s. you can customise the sentence however way you want, just make sure to include the parameters.

Full code:

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

  result += "my " + myNoun + " is very " + myAdjective + " and can " + myVerb + " very " + myAdverb;
  // Your code above this line
  return result;
}

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

wow. this is quite interesting. i have seen where my errors have been all along. You`ve quite helpful really.
Thanks a whole lot
:rofl::raising_hand_man:

1 Like

@beeshop I have the same issue. What did you correct?

i notice that i was spacing my wrongly in my ‘return result’ for instance, i typed;

return result += “My” + myNoun + “is quite” + myAdjective + “but it” + myVerb + “so” + myAdverb;
Instead of:
return result += "My " + myNoun + " is quite " + myAdjective + " but it " + myVerb + " so " + myAdverb;

but the main reason for my code not running was that i misplaced variables. My initial code looked lie this:

return result += “My” + “myNoun” + “is quite” + “myAdjective” + “but it” + “myVerb” + “so” + “myAdverb”;

instead of:
return result += "My " + myNoun + " is quite " + myAdjective + " but it " + myVerb + " so " + myAdverb;

so, i was bascially repeated already declared functions myNoun, myAdjective etc in the return result.
so try to check your code again. my final code nows looks like this:
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
// Your code below this line
var result = “”;

// Your code above this line
return result += "My " + myNoun + " is quite " + myAdjective + " but it " + myVerb + " so " + myAdverb;
}

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

hope it helps!