Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else...
-
Upload
griffin-cameron -
Category
Documents
-
view
219 -
download
0
description
Transcript of Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else...
![Page 1: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/1.jpg)
Complex Conditionals
![Page 2: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/2.jpg)
N-way decisions
• How to deal with more than 2 alternates?
• Nested else statements
![Page 3: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/3.jpg)
else if
![Page 4: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/4.jpg)
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
![Page 5: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/5.jpg)
Decision Treegrade < 60
F grade < 70
D grade < 80
C grade < 90
B A
![Page 6: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/6.jpg)
nested else
![Page 7: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/7.jpg)
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
![Page 8: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/8.jpg)
Exercise ResultsResults: 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
![Page 9: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/9.jpg)
switch
![Page 10: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/10.jpg)
switch
• When checking the same variable for equal to different values
switch(variable) { case “val1”: stmt1; break; case “val2”: stmt2; break; default: stmt;}
![Page 11: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/11.jpg)
Working with date
![Page 12: Complex Conditionals. N-way decisions How to deal with more than 2 alternates? Nested else statements.](https://reader036.fdocuments.in/reader036/viewer/2022062600/5a4d1b367f8b9ab05999d102/html5/thumbnails/12.jpg)
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