Number guesser project help

I have 2 questions.
Q1> I was able to make a guess, went to round 2. But after that, only “make a guess” is clickable, and I cannot clicked “next round” or get to round 3 onwards no mater how many times i make a guess. What’s wrong with my code?

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

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

const compareGuesses = (humanGuess,computerGuess,targetNumber) => {
  if (Math.abs(humanGuess - targetNumber) > Math.abs(computerGuess - targetNumber)){
    return false;
  } else if (Math.abs(humanGuess - targetNumber) <= Math.abs(computerGuess - targetNumber)) {
    return true;
  } else { return'error';}

function updateScore() {
  let compareGuesses =true;
  compareGuesses ? updateScore = 'human': updateScore = 'computer';

  if (updateScore = 'human'){
    humanScore ++ ;
  } else if (updateScore = 'computer'){
    computerScore ++ ;
  } else { return 'error';}
const advanceRound = () => 
 currentRoundNumber ++ ;

**Q2>**Also, I don’t understand below solution. The instruction says " Return true if the human player wins, and false if the computer player wins. " But there is no true/false value in the below code. Can someone explain?

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

Can you share the exercise url? So we can run the code in the lesson environment. Thank you

well, the result of a comparison is a Boolean, given the condition is met (true) or not met (false)

easy enough to prove:

const result = 5 === 5
console.log(typeof result)

Hi, thank you for your help! URL:

using the console (f12, then console tab), i get an error while playing the game:

game.js:33 Uncaught TypeError: updateScore is not a function
    at HTMLButtonElement.<anonymous> (game.js:33)

the code provided by the lesson attempts to call your function:

  // Update the correct score:

but looking at your function:

function updateScore() {

i don’t see a parameter to handle the argument. The instructions say to add a parameter:

Has a single parameter. This parameter will be a string value representing the winner.

1 Like

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.