JSFiddle - React, Tailwind, and code Playground

by Matthew Day

HTML

try { 
        if(x == "") throw "empty";
        if(isNaN(x)) throw "not a number";
        x = Number(x);
        if(x < 5) throw "too low";
        if(x > 10) throw "too high";
    }
    catch(err) {
        message.innerHTML = "Input is " + err;
    }

JavaScript

function yearOfBirth(age){
  if(age < 0){
    throw new Error("Age can not be nagative");
  } else {
    var year = 2018 - age;
    console.log(`I was born in ${year}`);
  }
}

function whoAmI(name, age) {
  console.log(`Hi, my name is ${name} and I'm ${age} years old.`);
  yearOfBirth(age);
}

whoAmI("Chris", -5);