Advertisement
karlakmkj

Sample for simple error

Dec 6th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function printOperations(a, b) {
  2.   if (typeof a !== 'number' || typeof b !== 'number') {
  3.     throw new Error('Both arguments must be numbers!');
  4.   }
  5.  
  6.   console.log(a + b, a / b);
  7. }
  8.  
  9. // The function call below should print: 12 1
  10. printOperations(6, 6);  //if string is entered, the above custom error message will be printed
  11.  
  12. function exclaim(name, count) {
  13.   for (let i = 0; i < count; i += 1) {
  14.     console.log(`${name}!`);
  15.   }
  16. }
  17.  
  18. // Exclaim 'Muriel!' six times
  19. exclaim('Muriel', 6);   //order must be correct - string and then number
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement