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

99
Vistas
Guessing game doesn't accept third variant of answer

I did a guessing game with the example from video lesson, but if i write the right answer on the third time, it says that i did not guess. The problem is there: if(tryCount == maxTryCount)? This code down below is from lesson.

var answer = parseInt(Math.random() * 100);
var userAnswer = +prompt("Угадай число от 0 до 100");
var maxTryCount = 5;

for(var tryCount = 1; tryCount < maxTryCount; tryCount++){
    if(userAnswer == answer){
        alert("Поздравляю, ты угадал!");
        break;      
    } else if(userAnswer > answer){
        alert("Ты ввёл слишком большое число.");
    } else if(userAnswer < answer){
        alert("Ты ввёл слишком маленькое число.");
    }

    userAnswer = +prompt("Попробуй ещё раз. Введи число от 1 до 100\n У тебя осталось " + (maxTryCount - tryCount) + " попыток");
}
if(tryCount == maxTryCount)
    alert("Ты проиграл!");
alert("Правильный ответ: " + answer);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I did it! If I change the loop condition to <= and change if(tryCount == maxTryCount) to if(tryCount > maxTryCount) then the third variant is accepted as "right".

about 4 years ago · Juan Pablo Isaza Denunciar
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