Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
Store in vars in a loop?

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!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!