File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 5
5
// However, if the denominator is zero you should throw the error, "Attempted to divide by zero."
6
6
7
7
// 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 ) ) ;
Original file line number Diff line number Diff line change 1
1
function gradeLabs ( labs ) {
2
2
for ( let i = 0 ; i < labs . length ; i ++ ) {
3
3
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
+ }
5
10
console . log ( `${ lab . student } code worked: ${ result === 27 } ` ) ;
6
11
}
7
12
}
@@ -22,3 +27,26 @@ let studentLabs = [
22
27
] ;
23
28
24
29
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 ) ;
You can’t perform that action at this time.
0 commit comments