Skip to content

Instantly share code, notes, and snippets.

@codecademydev

codecademydev/script.js Secret

Created Apr 10, 2021
Embed
What would you like to do?
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
// Generate random number between 0 - 9
const generateTarget = () => Math.floor(Math.random() * 10);
// Compare user and cpu guesses with target
const compareGuesses = (user, cpu, secret) => {
if( user < 0 || user > 9){
alert('Please pick a number between 0 and 9')
};
let userGuess = Math.abs(secret - user);
let cpuGuess = Math.abs(secret - cpu);
// True = user wins , False = cpu wins Does not matter if it goes over
return user === cpu ? true :
userGuess <= cpuGuess ? true :
false
};
// update score fn
const updateScore = (str) => {
str === 'human' ? humanScore++ : computerScore++;
};
// go to next round fn
const advanceRound = () => currentRoundNumber++;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment