-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditionals.js
More file actions
50 lines (39 loc) · 1.18 KB
/
conditionals.js
File metadata and controls
50 lines (39 loc) · 1.18 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
47
48
49
50
// CONDITIONALS
// Checks if something (i.e condition) is true before executing particular code
// COMPARATORS
// === is equal to
// !== in not equal to
// > is greater than
// < is less than
// >= is greater or equal to
// <= is lsser or equal to
// && AND - both conditionals must be true
// || OR - either conditional must be true
// === checks if value & data type are equal
var a = 1;
var b = "1";
if (a === b) {
console.log("Yes");
} else {
console.log("No");
}
// == only checks if values are equal
var c = 1;
var d = "1";
if (c == d) {
console.log("Yes");
} else {
console.log("No");
}
// Test Score Alerts
var testScore = Math.random();
testScore = Math.floor(testScore * 100) + 1;
if (testScore >= 85) {
alert("Your test score is " + testScore + "%." + " You are above average!");
} else if (testScore >= 70 && testScore <= 84) {
alert("Your test score is " + testScore + "%." + " You are average.");
} else if (testScore >= 50 && testScore <= 69) {
alert("Your test score is " + testScore + "%." + " You are below average.");
} else {
alert("Your test score is " + testScore + "%." + " You failed.");
}