I have no idea why the score wont change. I attempted to instruct as follow:
if the absolute value of “humanGuess” is less than the absolute value of the “computerGuess” then return true (else false )
I stored is value as “winner” and wrote if (winner = true ) {then add +1 to the “humanScore”
`let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
//console.log(`${currentRoundNumber}st round - ${computerScore}:computer score ${humanScore}:humanGuess score`)
const computerGuess = Math.floor(Math.random()*10)
// Write your code below:
const generateTarget = (target) =>{
target = Math.floor(Math.random()*10)
return target
}
let target = generateTarget()
let humanGuess = 4
const compareGuesses = (target , humanGuess , computerGuess) =>{
let humanDiff = Math.abs(target - humanGuess);
let compDiff = Math.abs(target - computerGuess);
if (humanDiff < compDiff){
return true
}
else{
return false
}
}
// this is the UPDATE SCORE AREA
const winner = compareGuesses(target , humanGuess , computerGuess)
const updateScore = () => {
if (compareGuesses === true) {
let humanScore = humanScore + 1
} else if (compareGuesses === false) {
let computerScore = computerScore + 1
}
const advanceRound =(currentRoundNumber)=>{
return currentRoundNumber + 1
}
advanceRound()
}
console.log(`${target}:target ${humanGuess}:humanGuess ${computerGuess}:computer guess ${winner}`)
/*
console.log('This is the hint below')
updateScore(false);
console.log(humanScore); // To confirm that this value increased by 1
updateScore('computer');
console.log(computerScore); // To confirm that this value increased by 1
*/
`