Skip to content

Commit 9b7353a

Browse files
committed
modified drinks-ex5 and grade-calculator
1 parent fa9f58e commit 9b7353a

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

‎Week2/homework/js-exercises/drinks-ex5.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let drinkTray = [];
22
const drinkTypes = ['cola', 'lemonade', 'water'];
33
let num = 0;
44
for (let i = 0; i < 5; i++) {
5-
drinkTray.push( " " + drinkTypes[num]);
5+
drinkTray.push(drinkTypes[num]);
66
if (i % 2 !== 0) {
77
num++
88
};
Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
function calculategrades(gradeInput) {
2+
let result = 0;
23
let gPercent = `${(gradeInput * 100) / 100}%`; //using this calculation to make the percentage of the grade.
34
switch (Math.floor(gradeInput/10)) { //Using Math.floor to round grades to largest integer and then read the reletive condition in the switch.
45
case 9:
5-
console.log(`You got a A (${gPercent})!`)
6-
break;
6+
result = "A";
7+
break;
78
case 8:
8-
console.log(`You got a B (${gPercent})!`)
9-
break;
9+
result = "B"
10+
break;
1011
case 7:
11-
console.log(`You got a C (${gPercent})!`)
12-
break;
12+
result = "C"
13+
break;
1314
case 6:
14-
console.log(`You got a D (${gPercent})!`)
15-
break;
15+
result = "D"
16+
break;
1617
case 5:
17-
console.log(`You got a E (${gPercent})!`)
18-
break;
18+
result = "E"
19+
break;
1920
case 4:
20-
console.log(`You got a F (${gPercent})!`)
21-
break;
21+
result = "F"
22+
break;
2223
case 3:
23-
console.log(`You got a F (${gPercent})!`)
24-
break;
24+
result = "F"
25+
break;
2526
case 2:
26-
console.log(`You got a F (${gPercent})!`)
27-
break;
27+
result = "F"
28+
break;
2829
case 1:
29-
console.log(`You got a F (${gPercent})!`)
30-
break;
30+
result = "F"
31+
break;
3132
case 0:
32-
console.log(`You got a F (${gPercent})!`)
33-
break;
33+
result = "F"
34+
break;
3435
}
36+
return `You got a ${result} (${gPercent})!`
3537
}
36-
calculategrades(96);
38+
let x = calculategrades(96);
39+
console.log(x);
3740

38-
console.log(`${grades(1)}`)
41+
42+
// console.log(`${grades(1)}`)
3943

0 commit comments

Comments
 (0)