Presentation is loading. Please wait.

Presentation is loading. Please wait.

Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.

Similar presentations


Presentation on theme: "Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements."— Presentation transcript:

1 Complex Conditionals

2 N-way decisions How to deal with more than 2 alternates? Nested else statements

3 else if

4 More complicated IF example Let’s assign letter grades to students! 90 - 100 – A 80 - 89 – B 70 - 79 – C 60 - 69 – D <60 – F

5 Decision Tree grade < 60 Fgrade < 70 Dgrade < 80 Cgrade < 90 BA

6 nested else

7 Exercise Choose a number from 1 to 100 If the number is greater than 50, STAND If you are seated and the number is greater than 25, RAISE YOUR RIGHT HAND If you are standing and the number is less than 75, RAISE YOUR RIGHT HAND

8 Exercise Results Results: 4 groups, 3 variables 0-25: seated, no hand raised 26-50: seated, right hand raised 51-75: standing, right hand raised 76-100: standing, no hand raised Notice that raised right hand has completely different meanings based on context

9 switch

10 When checking the same variable for equal to different values switch(variable) { case “val1”: stmt1; break; case “val2”: stmt2; break; default: stmt; }

11 Working with date

12 Date and Time (to help understand snippets) Full date is unfriendly format To get today’s date: var d = new Date(); To get the time: var time = d.getHours(); To get the day: var theDay = d.getDay(); w3schools http://www.w3schools.com/js/js_date_methods.asp


Download ppt "Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements."

Similar presentations


Ads by Google