File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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."
Original file line number Diff line number Diff line change 11function 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
917let 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
2432gradeLabs ( 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 ) ;
You can’t perform that action at this time.
0 commit comments