Where Does Java. Script Go? � Inside attributes like onclick � As a section of code in the body �Only � As special cases a function in a separate file �Can link to it like the css �We will use
Java. Script functions Collection of statements that can be invoked as a unit � Can take parameters � Can be used multiple times � Can call without knowing what they do or how �
Function format function name() { stmt; }
A Separate Java. Script File <script src="myscripts. js"></script> Myscript. js Java. Script option in komodo note that it’s an empty file but it can help you do NOT include the script tag
JAVASCRIPT FUNCTIONS WITH PARAMETERS
Function format function name(parm) { stmt; }
Parameter Name is a placeholder � Can be used anywhere in a function � Can be used as many times as you want � Can not change it � MUST supply value when call � Can be different everytime �
Passing Parameters HTML mypet(‘cow’); mypet(‘dog’); JS function mypet(pet) { alert(‘my pet: ‘+pet); }
Multiple Parameters Order matters � Need different names �
Passing Parameters HTML mypet(‘Mutt’, ’Jeff’); mypet(‘Jeff’, ’Mutt’); JS function taller(big, small) { alert (big+’ is taller than ‘+ small); }
Jsbin and console � � Jsbin is just like jsfiddle but it allows you to see the console Console. log(message);