Blanking on Word Blanks again

Blanking on Word Blanks again
0

Tell us what’s happening:
So I am trying to ‘parse’ the new variables into the existing, given text, is that right? I tried a few different things but I don’t think I am on the right track for some reason.

Your code so far


function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  // Your code below this line
  var result = "dog, big, ran, quickly";
var sentence = "It was really" + myAdjective + "and we" + myVerb + "ourselves" + myAdverb + ".";
  // Your code above this line
  return result;
}

// Change the words here to test your function
// function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
// var result = ("cat", "little", "hit", "slowly");
// var sentence = "It was really" + myAdjective + "and we" + myVerb + "ourselves" + myAdverb + ".";
// return result;
// }

Your browser information:

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

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

see the return result in the function? that means that the variable result is the one that counts. which is just four words. so you pass one of the tests because those are also the values of the variables. but not the other, because in the other case your variables have other values but the value of result doesn’t change, as it doesn’t have variables inside.

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {

var result = "cat, little, hit, slowly";

var sentence = "It was really" + myAdjective + "and we" + myVerb + "ourselves" + myAdverb + ".";

return result;

};

This seems to work to changed the variable words but then my second test fails.

so then, I need a second function statement?

it is the value of result that counts. sentence is not considered by the tests, whatever you put inside it, it is like it doesn’t exist

hmmm…
var result = "It was really " + myAdvective +… and so on and and so forth?

try!

remember to add the spaces! in your sentence variable you were missing various spaces

so for non-variable text a space at the end of string one and then before and after all but the final string (which should be your punctuation and doesn’t require a space before or after)?

where it is grammatically necessary to make sense of things

1 Like

(This is es6 syntax)
You should also learn about something called template literals, basically you use `` < those
For example

let sentence = `Hello, I'm ${firstName} and I like to ${activity}.`

I remember touching on literals briefly before I had a clue what an operator even was. I figured it out, but thank you anyway.

I don’t understand this correct solution below. Specifically, why we use “My “+myAdjective+” “+myNoun+” “+myVerb+” very “+myAdverb+”.” and not "My " + myAdjective + myNoun + myVerb + " very " + myAdverb ?

What I missed?

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;
}

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

doesn’t seem a good sentence, don’t you think?