try {
const joke = allProgrammingJokes[Math.floor(Math.random() * allProgrammingJokes.length)];
if (!getJoke(joke)) {
thrownewError("Joke not understood");
}
} catch (error) {
console.log("lol *upvotes*");
}
functiongetJoke(joke) {
// This function is intentionally flawed to always return false.// It's a part of the joke!returnfalse;
}
ECMAScript spec says Math.random must be less than 1. I was about to stop there, but a thought occurred to me: could the multiply with a float make a number large enough to floor to a different value for large enough values? 🤔
I imagine it’d have to be a ridiculously large number to amount enough floating point imprecision to matter, if so.
try { const joke = allProgrammingJokes[Math.floor(Math.random() * allProgrammingJokes.length)]; if (!getJoke(joke)) { throw new Error("Joke not understood"); } } catch (error) { console.log("lol *upvotes*"); } function getJoke(joke) { // This function is intentionally flawed to always return false. // It's a part of the joke! return false; }
This might throw array index out of bounds errors.
ECMAScript spec says Math.random must be less than 1. I was about to stop there, but a thought occurred to me: could the multiply with a float make a number large enough to floor to a different value for large enough values? 🤔
I imagine it’d have to be a ridiculously large number to amount enough floating point imprecision to matter, if so.