Skip to content

Commit dd6e2a7

Browse files
complete
1 parent 1cd23c5 commit dd6e2a7

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

exceptions/exercises/divide.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,16 @@
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+
let numerator = 0
10+
let denominator = 0
11+
function divide(numerator, denominator){
12+
if (denominator === 0){
13+
throw Error("Attempted to divide by zero.");
14+
} else {
15+
let result = numerator/denominator;
16+
return result;
17+
}
18+
};
19+
20+
console.log(divide(8,0));

exceptions/exercises/test-student-labs.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
function gradeLabs(labs) {
22
for (let i=0; i < labs.length; i++) {
33
let lab = labs[i];
4-
let result = lab.runLab(3);
4+
let result;
5+
try {
6+
result = lab.runLab(3);
7+
} catch(err) {
8+
console.log("Error thrown.");
9+
}
510
console.log(`${lab.student} code worked: ${result === 27}`);
611
}
712
}
@@ -22,3 +27,26 @@ let studentLabs = [
2227
];
2328

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

0 commit comments

Comments
 (0)