Thanks… I did find that as I looked online, but decided to use the arrow function… So now that I’ve caught up with everyone else on this, I did the following for the Math.abs - the numbers seem to generate fine, but for some reason it’s not printing out the “return”
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
const generateTarget= () => {
Math.floor(Math.random() * 9);
return Math.floor(Math.random() * 9);
};
generateTarget();
let targetNumber = generateTarget();
let humanTarget = Math.abs(humanScore - targetNumber);
let computerTarget = Math.abs(computerScore - targetNumber)
function compareGuesses(humanTarget, computerTarget, targetNumber){
if(humanTarget < computerTarget){
return true
}else if(humanTarget > computerTarget){
return false
}else{
return true
}
}
you don’t have a variable named target. What variable are we talking about? I thought you meant one of the parameters on this line:
function compareGuesses(humanTarget, computerTarget, targetNumber){
like I said in my answer, the values for parameters come from arguments at function call. You never call the compareGuesses. Would be a good challenge to do so
Given my explanation was generic on parameters, what I explained still applied. Parameters get there values from arguments. For example:
function greet(name){
return `greeting ${name}`
}
console.log(greet('thomas'))
the name parameter gets its value ('thomas' string) from the argument at function call. Which means if we want to greet another person we can easily do:
console.log(greet('stetim'))
so the same applies to your function, which is why I suggested you should add function calls for practice
I understand that.
However: if this function gets theinput for computerGuess from the webpage, the humanGuess from the input on the webpage, how does it get the “target” variable? it is not defined anywhere in the code.
no else is needed. Also, going back to my corrections on the other person’s code, Math.abs can be defined as a variable within the compareGuesses function
Hey everyone! I’m stuck right now inStep 5. Right now, I think I got the function right, but the console says that humanScore variable and computerScore are not defined. I really do not know what dumb thing I’m doing because even when I reassign the variables inside the function, it still gives the same error. I hope I was clear, and thank you to whoever helps!
Here’s my code:
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Randomizer
const generateTarget = () => {
return Math.floor(Math.random() * 10)
};
// The Game
let compareGuesses = (humanGuess, computerGuess, targetNumber) => {
let humanPoint = Math.abs(humanGuess - targetNumber);
let computerPoint = Math.abs(computerGuess - targetNumber);
if (humanPoint <= computerPoint) {
return true;
} else {
return false;
}
}
//Score Updater
const updateScore = (win) => {
if (win === 'human') {
humanScore += 1;
} else if (win === 'computer') {
computerScore += 1;
}
}
console.log(updateScore('human'));
Yes! That’s exactly what happens. But I don´t get why console.log(humanScore) would fix this whole thing. Although I understood what you meant by the function not returning anything.