Number guesser challenge / can't pass task 7

Welcome to the Get Help category!

This is where you can ask questions about your code. Some important things to remember when posting in this category :slight_smile:

  • Learn how to ask a good question and get a good answer!

  • Remember to include a link to the exercise you need help with!

  • If someone answers your question, please mark their response as a solution :white_check_mark:

  • Once you understand a new concept, come back and try to help someone else!

let humanScore = 0;

let computerScore = 0;

let currentRoundNumber = 1;

// Write your code below:

const generateTarget = function(){

return Math.floor(Math.random()*9);

}

const compareGuess = function (humanGuess, computerGuess,targetGuess){

if((Math.abs( humanGuess - targetGuess )) < (Math.abs(computerGuess - targetGuess))){

return true;

}

else if ((Math.abs( humanGuess - targetGuess )) > (Math.abs(computerGuess - targetGuess)))

return false;

else if((Math.abs( humanGuess - targetGuess )) === (Math.abs(computerGuess - targetGuess))){

return true;

}

else{

return invalid;

}

}

const updateScore = function(){

if(compareGuess){

humanScore += 1

}

else if(compareGuess === false){

computerScore += 1

}

currentRoundNumber += 1

}

updateScore(‘human’);

console.log(humanScore); // To confirm that this value increased by 1

updateScore(‘computer’);

console.log(computerScore); // To confirm that this value increased by 1

This is my code and i can’t pass task 7. Can you help me please thanks again.

Hello! Could you post any errors you’re getting, please? If you’re not getting errors, but undesirable behaviour, how so? Also, please see this guide on formatting code in posts.

Result i got using this code is not an error. I make a guess but i can’t make guess. That process doesn’t work.

Sorry, I don’t quite understand what’s happening (or rather not happening). Also, is there more code than the code that you’ve just shared?

I looked at the instructions for this project and if mine are not out-of-date …

you’re missing a parameter for the updateScore function ( - the parameter should be winner),

like this:
const updateScore = function(winner){

Also, the if-statement and else-if statement in that function should check whether winner is the string 'human' or 'computer' instead of checking whether compareGuess is true or false.
(Also, compareGuess was a function, not a boolean variable that stores true or false.)

Less importantly,
in a previous function, you have return invalid;
but there’s no variable named invalid,
so maybe that should be undefined or maybe false.

Also, please use the code formatting stuff (meaning the </> button) when you post code to make it easier to read.

1 Like

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