-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathlab.js
More file actions
47 lines (33 loc) · 796 Bytes
/
lab.js
File metadata and controls
47 lines (33 loc) · 796 Bytes
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
//Final Challenge: Student Grade Calculator
const student = {
name: "Amani",
scores: [80, 90, 75, 100]
};
function calculateAverage(scores) {
let total = 0;
for (let i = 0; i < scores.length; i++) {
total += scores[i];
}
return total / scores.length;
}
function getGrade(avg) {
if (avg >= 90) {
return "A";
} else if (avg >= 80) {
return "B";
} else if (avg >= 70) {
return "C";
} else if (avg >= 60) {
return "D";
} else {
return "F";
}
}
const average = calculateAverage(student.scores);
const grade = getGrade(average);
console.log("Name:", student.name);
console.log("Average:", Math.round(average));
console.log("Grade:", grade);
// I believe strings were the easiest.
// I believe objects might have been the most difficult
//