Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript.

Similar presentations


Presentation on theme: "JavaScript."— Presentation transcript:

1 JavaScript

2 JavaScript needs to be “called”
Need an event to change things Mouse actions onclick onmouseover onmouseout Other events: when a new page is loaded onload

3 onload Using JavaScript to create content No user input Comes up when page LOADS <body onload=“doitnow();”>

4 Calling JavaScript Inside of HTML Statement can be
On □ □ □ □ = “JavaScript stmt;” Statement can be assignment statement function call

5 function Collection of instructions Can be called many times
Called as a single statement

6 JavaScript function Set of instructions Followed step by step in order
Statement types: Variable declarations Assignment statements Functions calls Conditional statements

7 Declared Variables Explicitly define them
Can give them starting values JavaScript figures out data type

8 Data Types Strings Literals can be in ‘’ or “”
Set of functions that work on them Numbers Own set of functions, including Math functions Booleans True or false Own set of operators

9 Assignment Statements
Give a value to Value can be Variable Form field HTML element Variables Literals Operators Functions Form fields HTML elements

10 Conditional Statements (1 of 3)
Execute statements if the condition is true if (score==10) { returnmsg = "Awesome! "; } Execute one of 2 groups of statement depending On whether true or false if (score==10) { returnmsg = "Awesome! "; } else { returnmsg = "Keep trying! ";

11 Conditional Statements (2 of 3)
Execute group of statements depending on which condition is true if (num < 60) { grade = "F"; } else if (num < 70) { grade = "D"; } else if (num < 80) { grade = "C"; } else if (num < 90) { grade = "B"; } else { grade = "A"; }

12 Conditional Statements (3 of 3)
Execute each statement in order Can execute all if’s if (weather == "Sunny") { text = text + weather; } if (day == 0) { text = text + " Sunday"; text = text + " is "; if (temp < 60) { text = text + "cool"; else { text = text + "nice";


Download ppt "JavaScript."

Similar presentations


Ads by Google