JSFiddle - React, Tailwind, and code Playground
by grc4
HTML
<button onclick="run()">Run</button>
JavaScript
// scroll down to see the code with a brief explanation
// SPOILER ALERT!
function run() {
var mercyCounter = 0;
var getResult = function(n, notReadyYet) {
alert("Calculating results...");
if (mercyCounter++ > 20) return; // You're welcome
if (notReadyYet) {
setTimeout(getResult, 100, n);
} else {
sayResult(n);
}
return arguments.callee;
}
var sayResult = function(n) {
if (n >= 10) {
alert("That's a big number!");
}
if (n < 10) {
alert("That's a small number.");
}
return n;
} // <-- Put a semicolon there and it will work normally :p
// Without a semicolon, the sayResult function will be immediately
// invoked with the code below as one huge parameter, which will
// return the getResult function and assign it to sayResult...
(function() {
var input = parseInt(prompt("Please enter a number:"));
var result = getResult(input, true);
return result;
})();
}