-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBooleans.js
More file actions
46 lines (34 loc) · 1.19 KB
/
Booleans.js
File metadata and controls
46 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//Relational operators
document.write("3 > 4: " + (3 > 4) + "<br>");
document.write("3.5 < 7: " + (3.5 < 7) + "<br>");
document.write("3 == 3: " + (3 == 3) + "<br>");
//Why not this?
//3 = 3;
document.write("3 != 3: " + (3 != 3) + "<br>");
document.write("2 <= 1 + 1: " + (2 <= 1 + 1) + "<br>");
//Logical operators:
var p = true;
var q = false;
//Not:
document.write("Not true: " + !p + "<br>");
document.write("Not false: " + !q + "<br>");
//And:
document.write("true && true: " + (p && p) + "<br>");
document.write("true && false: " + (p && q) + "<br>");
document.write("false && true: " + (q && p) + "<br>");
document.write("false && false: " + (q && q) + "<br>");
//Or
document.write("true || true: " + (p || p) + "<br>");
document.write("true || false: " + (p || q) + "<br>");
document.write("false || true: " + (q || p) + "<br>");
document.write("false || false: " + (q || q) + "<br>");
//Exercises: what is the output of the following?
var a = p || !p;
var b = q || !q;
var c = p && !p;
var d = q && !q;
var e = !(!p || !q);
var f = !(!p || !p);
var g = p && q == !(!p || !q);
//How would I check to see if an number is between 1 and 10?
//Think carefully, it may not be as obvious as it seems!