Skip to content

Instantly share code, notes, and snippets.

@schesnowitz
Created February 17, 2023 23:10
Show Gist options
  • Save schesnowitz/8b06415b3f6a1c182533b3fbd7e2bd9e to your computer and use it in GitHub Desktop.
Save schesnowitz/8b06415b3f6a1c182533b3fbd7e2bd9e to your computer and use it in GitHub Desktop.
random math generator
let x = Math.floor(Math.random() * 100 + 1);
let y = Math.floor(Math.random() * 50 + 1);
sum = (x + y).toString();
sumOutput = (`${x} + ${y} = ${sum}`);
remainder = (x % y).toString();
remainderOutput = (`${x} % ${y} = ${remainder}`);
product = (x * y).toString();
productOutput = (`${x} X ${y} = ${product}`);
quotient = (x / y).toString();
quotientOutput = (`${x} / ${y} = ${quotient}`);
difference = (x - y).toString();
differenceOutput = (`${x} - ${y} = ${difference}`);
selection = difference
function printTheResults() {
if (selection === sum) {
return sumOutput
} else if (selection === remainder) {
return remainderOutput
} else if (selection === product) {
return productOutput
} else if (selection === quotient) {
return quotientOutput
} else if (selection === difference) {
return differenceOutput
}
}
console.log(printTheResults());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment