-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgradeExercise.js
More file actions
49 lines (44 loc) · 1.27 KB
/
gradeExercise.js
File metadata and controls
49 lines (44 loc) · 1.27 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
// Find the average of the array and assign a grade
// 1-59: f
// 60-69: D
// 70-79:C
// 80-89: B
// 90-99:A
const marks = [80,100,80];
function score(){
let sum = 0;
for(let i = 0; i<marks.length; i++){
sum += marks[i]
avg = sum / marks.length
}
console.log(avg)
if(avg < 60){
console.log('F');
} else if (avg < 70 && avg >=60){
console.log('D')
} else if (avg < 80 && avg >= 70){
console.log('C')
} else if (avg < 90 && avg >= 80){
console.log('B')
} else if (avg <= 100 && avg >= 90){
console.log('A')
}
// switch(avg){
// case (avg < 60):
// console.log('F')
// case (avg < 70 && avg > 60):
// console.log('D')
// return 'D'
// case (avg < 80 && avg > 70):
// console.log('C')
// case (avg < 90 && avg > 80):
// console.log('B')
// case (avg < 100 && avg > 90):
// console.log('A')
// }
}
score()
// Ideally since i was going to iterate an array
// I should have used the for of loop but i just decided
// to use the normal for loop to see if i could still properly
//use it