So, I have this tiny problem I can't solve, so I would appreciate it if you could help me. I made a programm which... well... just calculates. The program tries random number in a calculation and looks if that fits. Well, because the numbers are random generated thy often repeat themselves. Now I want to try write the already fitting calculations into vars and let the program compare the fitting calcs to the already stored calcs. If that's true nothing should happen it should just go on with the programm. Here's the loop:
//Vars
x = 3;
y = 81;
Ergebnis = 4680;
//Mehrere Variabeln oder nicht
mehrere = true;
ged = false;
end = false;
console.clear()
setTimeout(stoppy, 15000)
function stoppy() {
ged = true;
}
setTimeout(calc, 10)
setTimeout(alcd, 10)
function calc() {
console.log('Working...')
a = 0;
for(i = 2; i > 1; i++) {
randomNumberInRange = Math.floor(Math.random() * 100000) + 1
randomNumberInRange1 = Math.floor(Math.random() * 100000) + 1
if(ged == true) {
console.log('Stopped because it ran to long.')
break;
}
z = x*randomNumberInRange+y*randomNumberInRange1;
if(z == Ergebnis) {
console.log(x+'*'+randomNumberInRange+' + '+y+'*'+randomNumberInRange1+' = '+Ergebnis);
a++;
if(mehrere == false) {
break;
} else {}
if(a == 10) {
break;
}
}
}
}
Please don't change much about the original script. It would help very much if you would just add code. I hope you can help me. And please help me store the values outside of that loop. That would be nice. Thanks!