I’m a noob coder and I’m trying to make a small app that generates random math problems with x amount of digits. It works fine until I try something like multiplying two 9 digit numbers.
Here is the block of code that calculates the two randomly generated numbers:
let sum1 = 0
let sum2 = 0
function answer() {
let theAnswer = 0
scoreOnce = 1
if (operatorEl.textContent === "+") {
theAnswer = sum1 + sum2
fullsum.textContent = theAnswer
} else if (operatorEl.textContent === "-") {
theAnswer = sum1 - sum2
fullsum.textContent = theAnswer
} else if (operatorEl.textContent === "*") {
theAnswer = sum1 * sum2
fullsum.textContent = theAnswer
} else if (operatorEl.textContent === "รท") {
theAnswer = sum1 / sum2
fullsum.textContent = theAnswer
}
}
And this is how I generate the numbers (9 digit numbers in this case):
function generate9() {
sum1 = Math.floor(Math.random() * (999999999 - 100000000 +1)) + 100000000
topNum.textContent = sum1
sum2 = Math.floor(Math.random() * (sum1 - 100000000 +1)) + 100000000
botNum.textContent = sum2
fullsum.textContent = "____"
fullsum.style.color = "#FFFFFF"
inputEl.value = ''
scoreOnce = 0
}