Number Guesser Challenge Project (JavaScript)

Hello, @coursemaster74508, and welcome to the forums!

I just ran your code. It correctly determines the winner, but always updates the human score instead of updating the computer score when the computer wins. Re-read the instructions for writing the updateScore function:
Your code is expecting true or false, but that’s not what is passed.

Hi everyone!
I’m new to here and I’ve just started coding for 3 days recently. I got trouble with this code but didnt know where I was wrong. Please help me fix it and give me some advices!

thank you everyone

I´m a newby in JS. I can´t find the error in my code but nothing happens when I try to click ‘Make a guess’.

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

// Write your code below:
let generateTargetNumber = () => {
    return Math.floor(Math.random()*10);

function compareGuesses(humanGuess, computerGuess, targetGuess) {
    let userDistance = Math.abs(targetGuess - humanGuess);
    let computerDistance = Math.abs(targetGuess - computerGuess);
    //nur wenn Computer näher ist gewinnt Computer --> ansonsten gewinnt User
    if (computerDistance < userDistance) {
        return false;
    else {
        //bei "unentschieden" oder wenn User näher ist gewinnt User
        return true;

let updateScore = winner => {
    if(winner === 'human') {
        humanScore += 1;
    } else if (winner === 'computer') {
        computerScore +=1;

function advanceRound() {
    currentRoundNumber += 1;

because you have to use the same variable name which is use in all the rest of the program EVERYWHERE. Good luck :slight_smile:

Sorry … could you give me the precise line where I was wrong? Don´t get it :frowning:

You are writing the script.js file. Their is also a game.js file that is using the code you wrote in script.js to run the game. game.js is expecting exact variable/function names in script.js, you can look at game.js or the project instructions to see those names and match them to the ones in script.js


Yeah. SO , this is my first time here. I spent 30 mins breaking my head on figuring out the logic. Hope it works. Still haven’t figured out how to run it though.