Number Guesser Project working but not really

Hi, hope you’re all ok :slight_smile:

I’m new to coding and if you could help it will mean a lot.
Inumer guesser project

Code is working (not showing any errors)… BUT

  1. When it increment rounds by one… from round no. 1 it goes straight to round no.3 ? Later it works fine and counting rounds as it should.

  2. It adds points only to human player… It shows that computer Wins but scores still going to human.

Thank you for your help!

let humanScore = 0;

let computerScore = 0;

let currentRoundNumber = 1;

// Write your code below:

const generateTarget = (you) =>{

return Math.floor(Math.random()*10);  // step 3


const compareGuesses = (human,computer,target) => { //step 4

const computerD = Math.abs(target - computer);

const humanD = Math.abs(target - human);

if (humanD === computerD){

  return true;


else if (humanD < computerD){

  return true;

} else if(humanD > computerD){

  return false;

}else { return 'Error'}


const updateScore = (winner) => {

 winner ? humanScore++ : computerScore++;



advanceRound = () =>{




Hello and welcome!

The skipping of the second game is because you call advanceRound() in the end of the file. This logic is already handled from another js-file that is provided in the project so you can comment out or remove this line:

// advanceRound(); 

The incorrect counting of computer score has to do with incorrect use of ternary-operator. The ternary is usually used in a way similar to this but there are variations:

result = (condition) ? 'something' : 'somethingelse';

This line of code causes problems in your code:

winner ? humanScore++ : computerScore++;

If you replace that with a simple if/else-statement incrementing the correct variable then the computer score-keeping should work although it will be longer.

Thank you!

I’ll try this :slight_smile:

1 Like

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