Number Guesser project

Link to the exercise:

I keep getting error messages and don’t yet know how to run the program. Can anyone see where i made the crucial mistake? I checked with the other posts about this exercise.
Thanks in advance! This is my code so far:

let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;

// Write your code below:
function generateTarget = () => {
  return Math.floor(Math.random()* 10);

function compareGuesses (humanGuess, computerGuess, generateTarget) => {
  if (Math.abs(humanGuess - generateTarget) > Math.abs(computerGuess - generateTarget)){ 
    return false
} else if (Math.abs(humanGuess - generateTarget) < Math.abs(computerGuess - generateTarget)){ 
  return true
} else { return true }

const updateScore = winner => {
  if (winner === "human") {
   humanScore ++;
  } else if (winner ==="computer") {
    computerScore ++;

const advanceRound = () => {

the fat arrow or arrow function (=>), is a way of writing a function. Using both the arrow (which represents the function) and the function keyword can’t be right. Which syntax are you going to go for?

Okay, learned something there, still get the error though, can you see what else I’m missing?

I’ve got it! the assign marker missed at function compareGuesses, thanks anyway!

Presumably the error comes with a message for you to consider in order to be able to do something about it. Don’t try avoid it, find the solution through it.

Also, if you run your code after each change you make you’ll be immediately alerted about problems that should be fixed before you continue writing more code. And when that happens, you know it’s your last edit that caused it, because before that it ran.

1 Like

While you’re writing that code, you might for example decide that you want a function.

So you’d write a function that does nothing.

Run it. Runs? okay. Add something to it. Most useful functions accept input. Add that.
Run it.
Make the function print out the input it got to prove that it actually got there.
Call the function, or, obviously nothing will happen.
Run it. You should now expect it to print something, because you wrote such code.
Presumably the function should have a result. Say the result is 1. Make that so.
Run it.
Print out the result of calling your function.
Run it.
Presumably you would want to process the input in some way, so you’d continue with that.

… and so on

See what I’m getting at? You shouldn’t ever be in the situation of “here’s all this code, no idea what’s wrong with it”, at least not unless you’ve got some proper mystery.

Thanks, that is very helpfull, i have got to keep checking my code immediately after i make changes to it, i see that now. Haha and this was indeed not a proper mystery, thanks.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.