Skip to content

Commit 4d2974d

Browse files
committed
completed
1 parent 6f0a9ad commit 4d2974d

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

exceptions/exercises/divide.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
// Write a function called 'divide' that takes two parameters: a numerator and a denominator.
2+
let a = 10;
3+
let b = 0;
24

5+
function divide(numerator, denominator){
6+
if (denominator === 0) {
7+
throw Error('Attempted to divide by zero.');
8+
9+
} else {
10+
return numerator/denominator;
11+
}
12+
13+
}
14+
15+
console.log(divide(a, b));
316
// Your function should return the result of numerator / denominator.
417

518
// However, if the denominator is zero you should throw the error, "Attempted to divide by zero."
Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,55 @@
11
function gradeLabs(labs) {
22
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}`);
3+
let lab = labs[i];
4+
let result;
5+
6+
try{
7+
result = lab.run.Lab(3);
8+
console.log(`${lab.student} code worked: ${result === 27}`);
9+
}
10+
catch(error){
11+
result = "Error thrown";
12+
console.log(result);
13+
}
614
}
715
}
816

917
let studentLabs = [
1018
{
11-
student: 'Carly',
12-
runLab: function (num) {
19+
student: 'Carly',
20+
runLab: function (num) {
1321
return Math.pow(num, num);
14-
}
22+
}
1523
},
1624
{
17-
student: 'Erica',
18-
runLab: function (num) {
25+
student: 'Erica',
26+
runLab: function (num) {
1927
return num * num;
20-
}
28+
}
2129
}
2230
];
2331

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

0 commit comments

Comments
 (0)