Heya
Im doing the fullstack engineer course at the the Number Guesser project
under the javascript syntax 1 unit at functions
got 2 questions
- At step 5 I’m instructed as follows:
" Create an updateScore()
function. This function will be used to correctly increase the winner’s score after each round.
This function:
- Has a single parameter. This parameter will be a string value representing the winner.
- Increases the score variable (
humanScore
orcomputerScore
) by 1 depending on the winner passed in toupdateScore
. The string passed in will be either'human'
or'computer'
. - Does not need to return any value."
Given compareGuesses() function we did at step 4 is obviously needed to be passed as the parameter for this function
yet we instructed to compareGuesses() only return true or false
what do they mean here?
pass in the result from step 4s function but also ‘human’ or 'computer?
As i didnt understand the intention i went with using step 4’s function return value true/false
to be the one passed to the function to be created at step 5 updateScore()
which leads to my next question
- I finished all the steps till step 7
I tested the code and all functions under Vcode
everything works at the debug level
but when i run the game both my browser (downloaded the files) and in the codecademy environment
the computer score doesnt update when the computer wins
Any help would be appreciated
My code is below
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
//generates secret target number at start of new round
const generateTarget = () =>{
let num = Math.floor(Math.random()*10);
return num;
}
//compares guesses to determine who wins
const compareGuesses = (user,computer,target) =>{
if( user<0 || computer<0 ) {
return 'Invalid inputs numbers must be between 0 and 10';
}
let userRange = (target-user);
let computerRange = (target-computer);
if( target - user < 0 ) {
userRange = (userRange*(-1));
}else{
userRange;
}
if( target - computer < 0 ) {
computerRange =(computerRange*(-1));
}else{
computerRange;
}
if( userRange < computerRange || userRange === computerRange) {
return true;
}else {
return false;
}
}
// function updates score depending who wins
const updateScore = (str) =>{
if(str){
humanScore += 1;
}else{
computerScore += 1;
}
}
//advances round by 1
const advanceRound =() => {
return currentRoundNumber += 1;
}