Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda