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

95
Views
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 answers
Answer question

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 Report
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!