Week5 Video 2.4 Functions: Can't Skip Over Arguments

by Lucille Kenney

HTML

<b><p>You can't skip over an argument.</p>Open your console to see the output from this code!</b>
<p>Here we have a function that takes three arugments, and assigns them to three parameters.    </p>
<p>While you don't have to pass in three arguments (you might have only one or two), the only way to get a value into the third parameter is to pass three arguments, even if some are undefined.  </p>

JavaScript

/* When you do use parameters, you can't skip.
 */ 

function person(exNum, name, age, occupation){
    console.log(exNum + ": My name is: "+name);
	console.log(exNum + ": I am " +age + " years old");
	console.log(exNum + ": I am a "+occupation);
}

person(1, "Bob", 45, "builder"); //OK
person(2, "Bob", 45); //OK
person(3, "Bob", "builder"); //not quite right
person(4, "Bob", undefined, "builder"); //OK

//the following one won't parse and breaks the code completely 
//person("Bob", , "builder");