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

104
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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