Word Blanks Challenge - functions?

Hello,

I’m a bit confused, trying to understand “function” at the top and the given words at the bottom. How does the function know what words go with which part of the function?

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");
  1. At the top is the function declaration:

    function wordBlanks(...

  2. Inside the ( parens ) are one or more “arguments” - variables passed into the function:

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

  3. Declaring a function does not execute it; it has to be called:

    wordBlanks("dog", "big", "ran", "quickly");

    That executes wordBlanks, passing four arguments to it.

FYI: paste code in between triple back-ticks. See here for more:

The function assumes that the parameters passed (e.g. “dog”,“big”) are in the same order as the variables in the function declaration (e.g. myNoun, myAdjective). As such, it is entirely possible for someone to put a verb in place of a noun.

This is why when you will see function calls with ‘null’ passed as a parameter. The function has no way of knowing that you just decided not to have a value for a parameter.

As you might imagine, placing the incorrect parameter in a function call can have strange consequences. As such, developers often devote a certain amount of effort to checking the parameters. Sometimes it might be a simple as making sure that the parameter passed is the correct type (e.g integer, string) other times it might be more complex.

thank you … cleared the fog

thanks for the markdown tip …