File tree Expand file tree Collapse file tree 2 files changed +51
-18
lines changed Expand file tree Collapse file tree 2 files changed +51
-18
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
+ function divide ( numer , denom ) {
10
+ if ( denom === 0 ) {
11
+ throw Error ( "You can't divide by zero." ) ;
12
+ }
13
+ return numer / denom ;
14
+ }
Original file line number Diff line number Diff line change 1
1
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
+ }
7
12
}
8
13
9
14
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
+ } ,
22
27
] ;
23
28
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 ) ;
You can’t perform that action at this time.
0 commit comments