Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created January 31, 2020 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save codecademydev/d456e9f3c87ba9a28d3cfe6074eed1b9 to your computer and use it in GitHub Desktop.
Save codecademydev/d456e9f3c87ba9a28d3cfe6074eed1b9 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
//step 3
let generateTarget = () => {
return Math.floor(Math.random() * 9);
};
//step 4
let compareGuesses = (human, computer, target) => {
const userG = Math.abs(target - human);
const computerG = Math.abs(target - computer);
return userG <= computerG;
/*if (userG <= computerG) {
updateScore('human');
} else {
updateScore('computer');
}*/
};
//step 5
let updateScore = winner => {
if (winner === 'human') {
humanScore += 1;
} else if (winner === 'computer') {
computerScore += 1;
}
};
//step 6
function advanceRound() {
currentRoundNumber += 1;
};
@DannyRuda
Copy link

/!\ I don't know how my code doesn't let my humanScore +1 when human is winning, I can't find more mistake in my code and thats driving me mad please help ! /!\

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

// Write your code below: function generateTarget() { return Math.floor(Math.random() * 10); }

function compareGuesses(user, computer, target) { const userGuess = Math.abs(target - user); const computerGuess = Math.abs(target - computer); return userGuess <= computerGuess; /* if (userGuess <= computerGuess) { return updateScore("user"); } else if (computerGuess <= userGuess) { return updateScore("computer"); } */ }

function updateScore(winner) { if ("winner" === "user") { humanScore++; } else if ("winner" === "computer") { computerScore++; } }

function advanceRound() { return currentRoundNumber++; }

@mrstosh Your mistake is inside the code block of your function "updateScore". In the condition, that the if statement checks, you wrote
" "winner" === "user" " but because you used quotation marks around "winner", the programm treats that as a string and not as the parameter of the function. So, you just have to leave the quotation around "winner" in both if statement conditions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment