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");
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.