Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

248
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda