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

Post on 18-Jan-2018

219 views 0 download

description

else if

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

Complex Conditionals

N-way decisions

• How to deal with more than 2 alternates?

• Nested else statements

else if

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

Decision Treegrade < 60

F grade < 70

D grade < 80

C grade < 90

B A

nested else

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

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

switch

switch

• When checking the same variable for equal to different values

switch(variable) { case “val1”: stmt1; break; case “val2”: stmt2; break; default: stmt;}

Working with date

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