Skip to content

Commit a3357b2

Browse files
committed
modified: exceptions/exercises/divide.js
modified: exceptions/exercises/test-student-labs.js
1 parent 445e93c commit a3357b2

File tree

2 files changed

+51
-18
lines changed

2 files changed

+51
-18
lines changed

exceptions/exercises/divide.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@
55
// However, if the denominator is zero you should throw the error, "Attempted to divide by zero."
66

77
// Code your divide function here:
8+
9+
function divide(numer, denom) {
10+
if (denom === 0) {
11+
throw Error("You can't divide by zero.");
12+
}
13+
return numer / denom;
14+
}
Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,50 @@
11
function gradeLabs(labs) {
2-
for (let i=0; i < labs.length; i++) {
3-
let lab = labs[i];
4-
let result = lab.runLab(3);
5-
console.log(`${lab.student} code worked: ${result === 27}`);
6-
}
2+
for (let i = 0; i < labs.length; i++) {
3+
let lab = labs[i];
4+
try {
5+
result = lab.runLab(3);
6+
} catch (e) {
7+
// console.log("Student "+lab.student+" has not defined the runLab function correctly!");
8+
result = "Error Thrown";
9+
}
10+
console.log(`${lab.student} code worked: ${result} ${result === 27}`);
11+
}
712
}
813

914
let studentLabs = [
10-
{
11-
student: 'Carly',
12-
runLab: function (num) {
13-
return Math.pow(num, num);
14-
}
15-
},
16-
{
17-
student: 'Erica',
18-
runLab: function (num) {
19-
return num * num;
20-
}
21-
}
15+
{
16+
student: "Carly",
17+
runLab: function (num) {
18+
return Math.pow(num, num);
19+
},
20+
},
21+
{
22+
student: "Erica",
23+
runLab: function (num) {
24+
return num * num;
25+
},
26+
},
2227
];
2328

24-
gradeLabs(studentLabs);
29+
let studentLabs2 = [
30+
{
31+
student: "Blake",
32+
myCode: function (num) {
33+
return Math.pow(num, num);
34+
},
35+
},
36+
{
37+
student: "Jessica",
38+
runLab: function (num) {
39+
return Math.pow(num, num);
40+
},
41+
},
42+
{
43+
student: "Mya",
44+
runLab: function (num) {
45+
return num * num;
46+
},
47+
},
48+
];
49+
50+
gradeLabs(studentLabs2);

0 commit comments

Comments
 (0)