Advertisement
TlalocTev

Try Catch JS

Mar 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function myFunction() {
  2.     var message, x;
  3.     message = document.getElementById("message");
  4.     message.innerHTML = "";
  5.     x = document.getElementById("demo").value;
  6.     try {
  7.         if(x == "") throw "empty";
  8.         if(isNaN(x)) throw "not a number";
  9.         x = Number(x);
  10.         if(x < 5) throw "too low";
  11.         if(x > 10) throw "too high";
  12.     }
  13.     catch(err) {
  14.         message.innerHTML = "Input is " + err;
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement