JSFiddle - React, Tailwind, and code Playground
by redbmk
HTML
Don't push the red button: <button id="push-me"></button>
CSS
button {
width: 20px;
height: 20px;
background: red;
border-radius: 10px;
}
JavaScript
function beDangerous() {
var one = 1, rand = parseInt(Math.random() * 2);
if (rand === one) console.log("You Win");
else if (rand === zero) console.log("You Lose");
}
function warnUser(error) {
alert("Hey, something went wrong! Refresh the page");
throw error;
}
function runCode() {
try {
beDangerous();
} catch (e) {
warnUser(e);
}
}
document.getElementById("push-me").addEventListener("click", runCode);