Why it is not working?

game.js:18 Uncaught ReferenceError: generateTarget is not defined
    at HTMLButtonElement.<anonymous>

whenever I’m trying to click on make a guess.

my code:

let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;

// Write your code below:
//--------------------STEP 1---------------------//
const generateTarget = () => {
    return Math.floor(Math.random() * 10);
}
// Testing the generateTarget function
// console.log(generateTarget());

//--------------------STEP 2---------------------//
const compareGuesses = (humanGuess, computerGuess, targetGuess) => {
    const humanDifference = Math.abs(targetGuess - humanGuess)
    const computerDifference = Math.abs(targetGuess - computerGuess)
    return humanDifference <= computerDifference;
};

// Testing compareGuesses function
// console.log(compareGuesses());

//--------------------STEP 3---------------------//
const updateScore = (winner) => {
    if (winner === "human") {
        humanScore++;
    } else if (winner === "computer") {
        computerScore++;
    }
};

//--------------------STEP 4---------------------//
// Next round 1,2,3,4..
const advanceRound = () => currentRoundNumber++;

Apologies, I have just seen your issue.

In the generateTarget() definition you have not closed the { that you have opened for it. You can do this two ways, either you can close the bracket to close off the function, or you can make it a single line function instead like so:

const generateTarget = () => Math.floor(Math.random() * 10)

sorry but I don’t think that was the case… Anyway I figured it out.

1 Like

@lordshiv can you share with us how you figured it out? This could potentially help other learners who run into the same issue. :slight_smile:

1 Like