Download presentation
Presentation is loading. Please wait.
1
JavaScript conditional
2
Boolean Logic Basis for modern computer logic
George Boole Basis for modern computer logic Works with only two values George Boole was an english mathematician and philosopher. Born 1815, died 1864.
3
BOOLEAN VARIABLE OR EXPRESSION
Holds either true or false can pass as a literal Can be thought of as yes or no Open excel – type true or false into a cell, and show that excel automatically capitlizes & centers it. TRUE & FALSE are special values in excel.
4
Is greater than or equal to
Boolean expressions Creates a Boolean value from numbers or strings Operator Meaning == Is equal to != Is not equal > Is greater than < Is less than >= Is greater than or equal to <= Is less than or equal to
5
Conditionals Test if a Boolean expression is true or false
Allows a program to make a choice
6
IF … THEN … ELSE if (MUST BE LOWERCASE)
no else: do nothing if not true else: one or the other else if: series of choices
7
More complicated IF example
Let’s assign letter grades to students! – A – B – C – D <60 – F Nested If: =IF(H2>=90, “A”, If(H2 >=80, “B”, “C or Below”)) Longer Nested if: =IF(H2>=90, "A", IF(H2>=80, "B", IF(H2>=70, "C", IF(H2 >=60, "D", "Fail"))))
8
Decision Tree grade < 60 F grade < 70 D grade < 80 C
B A
9
In JavaScript 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"; }
10
In JavaScript JavaScript statement(s)
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"; } JavaScript statement(s)
11
Combining Boolean expressions
12
Operations on Booleans
AND OR Are all of them true? && Is it a big dog? (size==“big” && pet==“dog”) Number between 5 and 10 (num>=5 && num<=10) Are any of them true? || Is it either blue or black? (color==“blue” || color==“black”) Number less than 10 or greater than 20 (num<10 || num>20)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.