forked from wdi-sea-01/js_control_flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrade.js
More file actions
54 lines (47 loc) · 1.21 KB
/
grade.js
File metadata and controls
54 lines (47 loc) · 1.21 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
51
52
53
54
// -------------------------------------------------------------------------
// INSTRUCTIONS:
// -------------------------------------------------------------------------
//
// Output the following letter grade from a variable with with a test score.
// Display either "A", "B", "C", "D", or "F", for an score that is an integer
// between 0 and 100. **Bonus: Try it again with a switch statement **
//
// -------------------------------------------------------------------------
var score;
var grade;
// using if statement
score = 84;
if (score >= 90) {
grade = 'A';
} else if (score >= 80) {
grade = 'B';
} else if (score > 70) {
grade = 'C';
} else if (score > 60) {
grade = 'D';
} else {
grade = 'F';
}
console.log('score = ' + score + '; grade = ' + grade);
// using switch statement
score = 66;
switch(true){
case score >= 90:
grade = 'A';
break;
case score >= 80:
grade = 'B';
break;
case score >= 70:
grade = 'C';
break;
case score >= 60:
grade = 'D';
break;
case score >= 50:
grade = 'F';
break;
default:
grade = 'Unknown';
}
console.log('score = ' + score + '; grade = ' + grade);