Can somebody explain what I did wrong with this? When I play the game, no matter what the outcome is, it always says the computer wins, but I get a point.
Here is my full code
Can somebody explain what I did wrong with this? When I play the game, no matter what the outcome is, it always says the computer wins, but I get a point.
Here is my full code
here:
if (compareGuesses)
compareGuesses is the function. Which will always evaluate to true. Why would you use compareGuesses in this condition?
Well I guess I am kind of confused about what the true and false values represent in the if/else if statement that I wrote.
Make sure to follow the project steps closely. There are multiple JavaScript files in this project but you are only writing one of them.
Right, and I only edited the script.js file, is there something else I should be doing?
maybe you should log/print this value then? To see what it
It just comes out as [function: compareGuesses]. So now I understand why that would always evaluate to true, but I’m still a bit confused as to what I would put instead of that. In the solution I see they put
const updateScore = winner => {
if (winner === ‘human’) {
humanScore++;
} else if (winner === ‘computer’) {
computerScore++;
}
}
but I don’t really get where the ‘human’ and ‘computer’ values come from.
when you call the updateScore function, you can pass a string (argument).
Ok thank you that makes sense, but for some reason the computer always wins, even if my guess is closer.
Here is my updated code
What exactly are you trying to accomplish with line 12: secretNumber = generateTarget
?
Same advise as earlier: logging/print if you don’t know something or to inspect parts of your code
I was trying to set the secretNumber parameter equal to the random number I got in the generateTarget function which doesn’t really make sense I guess. I removed that and it fixed it thank you!
Hi I’m having trouble solving this little program: Im not to sure where to go next? If anyone can help or bump me in the right direction It will be great.
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
let generateTarget = Math.floor(Math.random()*10)+1;
console.log('Random number ' + generateTarget);
let computerGuess = Math.floor(Math.random()*10)+1;
console.log('computer guesses '+ computerGuess);
const checkHumanGuess {
if ( humanGuess < 0 || humanGuess >9) {
conssole.log('This is behond the range of numbers');
}
}
let compareGuesses=(humanGuess,computerGuess,generateTarget) => {
if(Math.abs(humanGuess,generateTarget)< Math.abs(computerGuess,generateTarget)){return true
console.log('human wins')
humanScore++;}else return false
console.log('computer wins')
computerScore ++;
}
let updateScore = (compareGuesses) ? 'human wins' : 'computer wins';
console.log(updateScore);
console.log(humanScore);
this:
const checkHumanGuess {
does not look like a valid way to declare a function
thanks, ill get rid of it.
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
const generateTarget = () => {
let secretNumber = Math.floor(Math.random()*10)+1;
return secretNumber;
}
const compareGuesses = (humanGuess,computerGuess,secretNumber) => {
if (Math.abs(secretNumber - humanGuess) < Math.abs(secretNumber - computerGuess))
{
return true;
console.log(‘human wins’);
}else if (Math.abs(secretNumber-humanGuess) < Math.abs(secretNumber-computerGuess)) {
return true;
}else {
return false;
console.log(‘computer wins’)
}
console.log(computerGuess);
}
const updateScore = () => { if(true) {humanScore++;} else {computerScore++}}