I’m currently on Question 7 on the project, and I am trying to create a separate function to find the absolute value and distance between the human guess, the computer guess, and the target number. (I have already completed the base project successfully.)
I’m currently on Question 7 on the project, and I am trying to create a separate function to find the absolute value and distance between the human guess, the computer guess, and the target number.
I have created two functions, one named
getAbsoluteDistanceHuman, and another named
getAbsoluteDistanceComputer. For both functions, I’ve used two parameters:
For the first function, I created a constant variable, named
humanDifference, where I used Math.abs to find the absolute difference between the
targetNumber, and then I returned this variable. I done the same for the second function, but changed the function’s name to
I created one last function, called
compareGuesses, used the two constant variables and returned
humanDifference <= computerDifference;, which will compare the two variables, using boolean rules.
However, the code doesn’t work when ran on the browser.
I am shown to have won the game when I was supposed to lose.
If you are able to review my code attached here on GitHub, that would be great:
I am more into what I should improve on in my code instead of just hearing what I have done wrong. Thank you.