And return true if any of these conditions is fulfilled. But I am getting “Computer Wins” every time there is a tie.
I am logging the values of the guesses and target on the console, as I wanted to check if these are indeed the values selected, and they are, so I can’t really get to the bottom of it.
The code that calls this function is located in the game.js file. It doesn’t pass an argument to the function, so you shouldn’t be accepting a parameter.
No. It only matters that the function increments currentRoundNumber each time it is called, so there is no reason for an if statement. This function is a perfect candidate for a concise body arrow function, since it only has a single task:
You very much over complicated this project. Stick to what the steps tell you to do. Also you should be able to accomplish the compareGuesses function with only one if statement
Hello, my name is Christine and this is day 12 of my Javascript adventure. I have been teaching music for 30 years but I’ve always wanted to learn to code and I finally have the time! I love it and plan to continue.
Here is my completed “Number Guesser” project. It works!
Hi everyone,
It’s my first time on the forum, thank you in advance for your help. I’m struggling with this exercice.
Nothing happens at any level when I click on the "Make a guess"and I don’t understand why and what I missed with my function compareGuesses() (line 11).
When writing an if else statement, is there supposed to be a condition for the else?
Why are you declaring currentRoundNumber twice? It is already declared as a global variable at the top of your code.
It’s my mistake I didn’t realized that currentRoundNumber was on top.
For the others stuff I effectively forgot an if line 16 and also an error of syntax line 25.
It seems to work right now.
Just a quick question I’m not sure to understand the logic the compareGuesses() of the correction. The return is necessarily considered as true, that why we don’t need create other conditions with >= and === ?
For your updateScore function, “winner” is a parameter that is being inputted into the function when we call it. Our code will either input ‘human’ or ‘computer’ when calling the updateScore function depending on who wins. Our compareGuesses function returns either ‘true’ or ‘false’. We did not have to actually code the part that says the winner is ‘human’ or ‘computer’. That part is probably in the coded section that CA already provided. We aren’t trying to declare the who the winner is in our updateScore function like you were trying to do. We are merely adding a point to the winner that has been declared for us in a hidden part (CA’s provided code) that works in conjuction with our compareGuesses function.
So, when the code actually calls for the updateScore function, it will look something like
Blockquote
updateScore(‘human’); or updateScore(‘computer’);
FYI, we didn’t actually have to call in the updateScore function for this project, so we didn’t have to actually write the code like above.
With that in mind, our updateScore function will be read like,
if winner === ‘human’, then humanScore += 1, else if winner === ‘computer’, then computerScore +=1