Well, a comparison has only two possible outcomes: true, false
a comparison results in a boolean value:
console.log(typeof(5===5))
Well, a comparison has only two possible outcomes: true, false
a comparison results in a boolean value:
console.log(typeof(5===5))
Ok that makes total senses. So if humanDifference <= computerDifference
is true, it will return true
but if it isn’t it will return as false
. Thanks for that!
feel free to contribute
yes
At least I don t think I made any mistakes
I have a question about the solution code. When creating the compareGuesses function, could we use an if/else statement? Also the instructions say:
true
if the human player wins, and false
if the computer player wins.How is that reflected into this code?
How To Solve The “alert()
” function properly?
My code is Here.
Even though it’s working for the alert function but the problem is game still declaring the result and the Computer wining the game.
Please check my code and help me to fix it.
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
const generateTarget = () => {
Math.floor(Math.random() * 10);
};
const compareGuesses = (userGuess, computerGuess, targetGuess) => {
const targetGuess = generateTarget();
const humanDifference = Math.abs(targetGuess - userGuess);
const computerDifference = Math.abs(targetGuess - computerGuess);
return humanDifference <= computerDifference;
};
const updateScore = winner => {
if(winner === ‘human’) {
humanScore++;
} else if(winner === ‘computer’) {
computerScore++;
} else {
console.log(‘Error’);
};
};
const advanceRound = () => {
currentRoundNumber++;
};
This is my code for the game and I’m not sure why it’s not working, please could someone give me some advice.
Thank you.
You’re missing something in the generateTarget()
function
HI everyone. Here is the code I’ve written down for this challenge. It doesn’t work as expected. Can someone correct my code?
Here is the code
const generateTarget=()=>{
return Math.floor(10*Math.random());
}
function compareGuesses(computerGuess,userGuess,targetGuess){
const userDiff=Math.abs(userGuess-targetGuess);
const computerDiff=Math.abs(computerGuess-targetGuess);
if (userDiff<=computerDiff) {
return true;
}
else {
return false;
}
}
function updateScore(winner){
if (winner===‘human’){
humanScore=humanScore+1;
}
else{
computerScore=computerScore+1;
}
}
function advanceRound(){
currentRoundNumber=currentRoundNumber+1;
}
mine
Here, it might help
i think one of the major thing to refactor is the compareGuesses function.
man, my wild guess is, it has something to do with the game.js…
What am I missing in the code?
When I run the game nothing happens, no error, no response and I’m not sure why I’ve checked the codecademy code and mine is almost exactly the same
You can find my Project below. If you can check please don’t hassitate to criticise about improvements can be done. Thanks.
I also did it in game.js. on line 21 i put the condition but the result is same. Pop UP comes up but behind the game computer win.