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

170
Views
The second function(guess( )) dosent run by click event

Im trying to write a guess number app. it contains two function, the first which is startGame() works properly(receive the max number and then dissapear by taking the hidden class). but the second one which is suppose receive the users guess and check the users guess with the target number to see if they are equal dosent work. Heres the html and javascript source code.

const stage2 = document.getElementById('stage2');
const maximuminput = document.getElementById('maximum');
const startbutton = document.getElementById('start');
const guessinput = document.getElementById('guess-number');
const guessbutton = document.getElementById('guess-button');
const chancesspan = document.getElementById('chances');


let maximumNumber, totalChances, targetNumber;

startbutton.addEventListener('click', startGame);
function startGame(){
  maximumNumber = Number(maximuminput.value);

  if(maximumNumber > 10) {
      targetNumber = Math.floor(Math.random() * (maximumNumber + 1));
      totalChances = Math.floor(Math.log2(maximumNumber)) + 1;
      chancesspan.textContent = totalChances;
      stage1.classList.toggle('hidden');
      stage2.classList.toggle('hidden');
  }else {
      const p = document.querySelector('#stage1 p');
      p.outerHTML = '<P class="red">عدد وارد شده باید بزرگتر از 10 باشد</P>'
  }
}

guessbutton.addEventListener('click', guess);

function guess(){
  let yourguess = NUmber(guessinput.value);
  if(yourguess == targetNumber){
      stage2.innerHTML = '<p class="blue">تبریک شما موفق شدید</p>';
      return;

  }else if(yourguess > targetNumber) {
      const status = document.getElementById('status');
      status.innerHTML += `<span class="red">${yourguess}</span>`;
  }else {
      const status = document.getElementById('status');
      status.innerHTML += `<span class="red">${yourguess}</span>`;
  }

  remainingChances = Number(chancesspan.textContent);
  remainingChances -- ;
  if(remainingChances > 0 ){
      chancesspan.textContent = remainingChances;
  }else {
      stage2.innerHTML = '<p class="red>!متاسفانه فرصت شما به پایان رسید</p>"'
  }
}```



about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You seem to have a typo here

let yourguess = NUmber(guessinput.value);

let yourguess = Number(guessinput.value);

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!