JSFiddle - React, Tailwind, and code Playground
by rushtonmd
HTML
<input id="myinput">
<button id="who">Did they break it?</button>
<span id="message"><span>
JavaScript
// This function should NOT throw an exception
// because the output is strictly defined
function whoBrokeIt(name) {
if (name === "Adam") return "Yep!";
return "Nope";
}
// Try with
// "Adam"
// "Paul"
// {firstname:"Rad",lastname:"Butoni",age:97}
// new Error("error message")
// Wirin' up stuff - do you really need a try/catch??
$('#who').on('click', function (event) {
try {
var response = whoBrokeIt($('#myinput').val());
$('#message').html(response);
} catch (error) {
alert("WARNING! " + error.message);
}
});