Number Guesser Help -- Script won't award Computer points

Hi there forums!

I am having some issue with my code for the number guesser assignment, specifically the function for updating the score. I think it is an issue with not correctly understanding true vs. false/truthy vs. falsey but I’m still not sure…

The game almost runs correctly except for that every time that the computer wins, the human is still awarded the point. I imagine that is because my script for the function compareGuesses() is not running past the first conditional statement but I’m not sure why that is? Help please!

Hi @sarahswids
the function responsible for correctly updating the score is updateScore. This should be as described in step 5:

The string passed in will be either 'human' or 'computer'.

In your function, you’re not doing anything with the parameter ‘winner’.

Am I meant to understand that the rest of the code for this program will convert my “true” or “false” evaluation from the compareGuesses() function and input either “human” or “computer” as the argument in the updateScore() function for me? This wasn’t very clear to me in the instructions…

In the exercise you only write functions. You don’t write any function calls. All of that is done by the prewritten code in the file ‘game.js’. Therefore you have to follow the instructions very closely. And how the function is invoked is described well in step 5.
This is how it is called:

  const winner = humanIsWinner ? 'human' : 'computer'
// Update the correct score:
  updateScore(winner);

Hey sarahswids
apart from what @mirja_t explained, I think the problem you’re encountering

every time that the computer wins, the human is still awarded the point.

is specifically related to the logic of your code.

Commonly, the winner of a bet should be the one that gets the closest to the actual result. Thus, line 15 is roughly saying “yo that dumb machine lost the bet, return true to crown the human race as superior”.

Which is what updateScore() does when is called.

I imagine that is because my script for the function compareGuesses() is not running past the first conditional statement but I’m not sure why that is?

In order to refute the first conditional and enter in the second, the second condition must be true, so the number guessed by the human must be farther away from the target number than the computer guess.
In this case the Computer wins and the compareGuesses() return false.

A small example coming from the Victorian era:

hope this helps :slight_smile:

Just an update about this, quite the coincidence I just met this exercise on the back-end course.

Step4 states:

Determines which player (human or computer) wins based on which guess is closest to the target.

so I was actually correct yesterday supposing that:

Commonly, the winner of a bet should be the one that gets the closest to the actual result.

Regarding your question:

Am I meant to understand that the rest of the code for this program will convert my “true” or “false” evaluation from the compareGuesses() function and input either “human” or “computer” as the argument in the updateScore() function for me?

This is the code from game.js that does exactly that:

  // Determine if the human or computer wins:
  const humanIsWinner = compareGuesses(currentHumanGuess, computerGuess, target)
  const winner = humanIsWinner ? 'human' : 'computer'

  // Update the correct score:
  updateScore(winner);

it gets called whenever the button “Make a guess” is clicked:

const guessButton = document.getElementById('guess');

guessButton.addEventListener('click', () => {
//some code continuation..

Cheers,