I don’t understand why this is right! I caved in and hit the “Get a hint” button to get the missing information. My original code was way off.
Not sure how I was able to pass the 3 required items below with this line of code. result+= “My “+myAdjective+” “+myNoun+” “+myVerb+” very “+myAdverb+”.”;
Passed
wordBlanks("","","","") should return a string.
Passed
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).
Passed
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).
Your code so far
var
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
// Your code below this line
var result = "";
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");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.
If you add console.log(result) as last line before the “your code above this line”, you will see printed in the console the string
You will see that you have created a string with the arguments of the function (last line of the whole code) in the place of the variables. You can change those arguments and you will see the text in the console change
But right now you just need to understand how to concatenate strings contained in variables with other strings , the function part will be explained later
I even played around with the code. I was able to add to it.
I understand concatenation. What I don’t understand is how it knows where out pull the word list from based on the code. I’m going to keep playing with it till I get it.
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb, newword) {
// Your code below this line
var result = "";
result+= "My "+myAdjective+" "+myNoun+" "+myVerb+" very "+myAdverb+" "+newword+".";
// Your code above this line
return result;
console.log(result)
}
// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly", "outside");
This is a function call (last line of the code), the values in the parenthesis are the values that are passed in the function
This is the function declaration, the variables in the parenthesis are the parameters - when a function is called the code is executed passing the arguments in the function parameters
Functions is a future subject, you will find it in a few lessons and understand what happens here better
This is the command to print things to the console, though you should put it before the return statement if you want it to be executed
This is the return statement, and in this way you declare what value should be returned from the function
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.