Number Guesser alert()

I’m trying to do one of the extra bits in the Number Guesser project from the Full-Stack Developer path, but my alert never pops up. It also doesn’t prevent anyone from guessing numbers below 0 or above 9. Can someone look at my code and tell me what I’m doing wrong?

let humanScore = 0;

let computerScore = 0;

let currentRoundNumber = 1;

// Write your code below:

function generateTarget() {

  return Math.floor(Math.random() * 10);

}

function checkUser(human) {

    if (human < 0 || human > 9) {

        alert(message, 'You are disqualified. Please choose a number between 1 and 9.');

        return false;

    }

}

function compareGuesses(human, computer, secretNum) {

    const uNum = Math.abs(secretNum - human);

    const cNum = Math.abs(secretNum - computer);

    return uNum <= cNum;

}

function updateScore(winner) {

  if (winner === 'human') {

    humanScore += 1;

  } else if (winner === 'computer') {

    computerScore += 1;

  }

}

function advanceRound() {

    currentRoundNumber =+ 1;

}

Hi,

If this is all your code, you’re missing an area where you invoke your functions (sometimes done in a main() function, but not necessarily so).

With what’s written, it’s clear you have some global variables declared, and some functions defined. But you’re not asking the code to do anything more than that.

Hey @abbielassiter
have a look at what the instructions say about the functions you should write from steps 1-8.
They are very clear about the way, the functions should be written because they call them in game.js.
They don’t call any extra functions. So either you do that by interacting with the provided HTML (get the value from the input) or you simply make the check within a function that gets called in game.js.

(@toastedpitabread this exercise is tricky to help with as there is a lot of code already provided in different files.)

1 Like

Thank you! It works now! I just had to return the alert in the original function and then call it in the compareGuesses() function!