JAVASCRIPT FUNCTIONS Where Does Java Script Go Inside

  • Slides: 12
Download presentation
JAVASCRIPT FUNCTIONS

JAVASCRIPT FUNCTIONS

Where Does Java. Script Go? � Inside attributes like onclick � As a section

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 �

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; }

Function format function name() { stmt; }

A Separate Java. Script File <script src='data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20415%20289%22%3E%3C/svg%3E' data-src="myscripts. js"></script> Myscript. js Java. Script option in

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

JAVASCRIPT FUNCTIONS WITH PARAMETERS

Function format function name(parm) { stmt; }

Function format function name(parm) { stmt; }

Parameter Name is a placeholder � Can be used anywhere in a function �

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); }

Passing Parameters HTML mypet(‘cow’); mypet(‘dog’); JS function mypet(pet) { alert(‘my pet: ‘+pet); }

Multiple Parameters Order matters � Need different names �

Multiple Parameters Order matters � Need different names �

Passing Parameters HTML mypet(‘Mutt’, ’Jeff’); mypet(‘Jeff’, ’Mutt’); JS function taller(big, small) { alert (big+’

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

Jsbin and console � � Jsbin is just like jsfiddle but it allows you to see the console Console. log(message);