Hey there,

I’m working on the Number Guesser project currently. I’m trying to code the `compareGuesses`

function and I can’t figure out why it won’t work. I was able to create what feels like a longer means of writing the function so it works but I can’t find out why my initial try didn’t work as well - it wouldn’t give me any errors, it just logged ‘false’ no matter what.

**Here’s the working code:**

```
const generateTarget = () => Math.floor(Math.random() * 10);
let targetNumber = generateTarget();
let humanGuess = 8;
let computerGuess = 9;
let humanRange = Math.abs(humanGuess - targetNumber);
let computerRange = Math.abs(computerGuess - targetNumber);
const compareGuesses = (humanGuess, computerGuess, targetNumber) => {
if ((humanRange === computerRange) || (humanRange < computerRange)) {
return true;
} else {
return false;
}
}
```

**Here’s the broken code where I can’t understand why it’s broken:**

```
const generateTarget = () => Math.floor(Math.random() * 10);
let targetNumber = generateTarget();
let humanGuess = 8;
let computerGuess = 9;
const compareGuesses = (humanGuess, computerGuess, targetNumber) => {
if ((Math.abs(humanGuess - targetNumber)) === (Math.abs(computerGuess - targetNumber))){
return true;
}
else if ((Math.abs(humanGuess - targetNumber)) < (Math.abs(computerGuess - targetNumber))) {
return true;
}
else {
return false;
}
}
console.log(compareGuesses());
```

Some more things to help with! So, I originally didn’t use the:

```
let humanGuess =
let computerGuess =
```

and I was just doing a `console.log(compareGuesses(9, 8, );`

. It felt wrong to have the empty parameter but, since I already defined it with let `targetNumber = generateTarget();`

it didn’t seem like I should also be defining it in the console.log(). How would I do this?

Last question:

I tried to define `let targetNumber = generateTarget();`

inside the `compareGuesses()`

function but before the if statement and it sent back an error. Any ideas why? Is it proper to define targetNumber above the function?

I really appreciate any time you spend in helping me understand this and, from a new coder, the extra help on the forum is SO helpful. So, thank you in advance!

UPDATE (kind of):

So I still haven’t answered any of those above questions but I did continue going through the exercise with the working code and…it doesn’t work! I’ve searched through other people’s solutions and I have no clue why there’s would work and mine wouldn’t. Please help! Here is my full script.js code:

```
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
const generateTarget = () => Math.floor(Math.random() * 10);
let targetNumber = generateTarget();
let humanRange = Math.abs(humanGuess - targetNumber);
let computerRange = Math.abs(computerGuess - targetNumber);
const compareGuesses = (humanGuess, computerGuess, targetNumber) => {
if ((humanRange === computerRange) || (humanRange < computerRange)) {
return true;
} else {
return false;
}
}
const updateScore = winner => {
if (winner === 'human'){
humanScore ++;
}
else {
computerScore ++;
}
}
const advanceRound = () => {
return currentRoundNumber++;
};
```

Well, as long as no one has solved this. I’ll continue adding to the confusion. When I include

```
let humanGuess = 5;
let computerGuess = generateTarget();
```

in my code (in between the `let targetNumber = generateTarget()`

and `let humanRange = Math.abs(humansGuess - targetNumber);`

). The actual UX/UI in my browser works but when I remove those two lines of code, there’s no reaction to me pressing Make a Guess.