Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae5606a

Browse files
committed
added grade calculator
1 parent 34ef5c7 commit ae5606a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Week2/grade calculateor.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const calculateGrades = (grade) => {
4+
let gradeCalc = grade;
5+
// Uses if statement to check valid grade
6+
if (gradeCalc >= 0 && gradeCalc <= 100) {
7+
// here we start with if statement to check which grade should be fit to our student
8+
let grade;
9+
if (gradeCalc >= 90) {
10+
grade = 'A';
11+
} else if (gradeCalc >= 80) {
12+
grade = 'B';
13+
} else if (gradeCalc >= 70) {
14+
grade = 'C';
15+
} else if (gradeCalc >= 60) {
16+
grade = 'D';
17+
} else if (gradeCalc >= 50) {
18+
grade = 'E';
19+
} else {
20+
grade = 'F';
21+
}
22+
return `You got a ${grade} (${gradeCalc}%)!`;
23+
} else {
24+
// this else statement helps us to show error message when user input the value if it's wrong
25+
return 'Please type valid grade!';
26+
}
27+
};
28+
29+
console.log(calculateGrades(100));
30+
console.log(calculateGrades(89));
31+
console.log(calculateGrades(79));
32+
console.log(calculateGrades(69));
33+
console.log(calculateGrades(59));
34+
console.log(calculateGrades(49));

0 commit comments

Comments
 (0)