Skip to content

Commit

Permalink
Add error catching to division function
Browse files Browse the repository at this point in the history
  • Loading branch information
brook7G committed May 13, 2024
1 parent 20178dc commit 2a9a340
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lesson-20/Practice/practice.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,20 @@ function div(a, b){
return a/b;
};
console.log(div(10,5));
console.log(div(10,0));
console.log(div(10,0));
//
//
console.log("");
console.log("EXERCISE:-2");
//
//
let numbers =[10, 40, 0, 20, 50]
for(let i=0; i<numbers.length; i++) {
let result;
try{
result =div(1000, numbers[i]);
}catch(e){
result= e.message;
}
console.log(result);
}

0 comments on commit 2a9a340

Please sign in to comment.