Number Guesser Project Function not working

Hello, I am working on the Number Guesser project in JavaScript (I don’t know how to tag this project) and I wrote some code that isn’t working. It’s returning false when it should return true. If you could please have a look at it and help me figure out why this might be I would really appreciate it. I haven’t been able to figure it out all day :frowning: Thank you!! I’m sorry if its really obvious!

const compareGuesses = (user, guess, computerGuess) => {
const userScore = (user, guess)=> {return user - guess};
const compScore = (computerGuess, guess)=> {return computerGuess - guess};
if (compScore < userScore) {return false}
else {return true} };

console.log(compareGuesses(2, 5,9));

I changed it a little bit because I noticed a flaw, but it still doesn’t work.

const compareGuesses = (user, guess,computerGuess) => { 
    const userScore = (user, guess)=> {
      if (user > guess) {return user - guess}    
      else {return guess - user}};
    const compScore = (computerGuess, guess)=> {
      if (computerGuess > guess) {return computerGuess - guess} 
      else {return guess - computerGuess}};
     if (compScore < userScore) {return false}
      else {return true}  };

console.log(compareGuesses(1, 1, 5));

You forgot to call some of the functions you created.

In the second version, you had userScore as a function and compScore also as a function, so you could change the last lines of the compareGuesses function to be

     if (compScore(computerGuess, guess) < userScore(user, guess)) {return false}
      else {return true}  };

so that those functions are called.

version for originally posted code
const compareGuesses = (user, guess, computerGuess) => {
  const userScore = (user, guess)=> {return Math.abs(user - guess)};
  const compScore = (computerGuess, guess)=> {return Math.abs(computerGuess - guess)};
  if (compScore(computerGuess, guess) < userScore(user, guess)) {return false}
  else {return true} };

console.log(compareGuesses(2, 5,9));

Although you can use variables that contain numbers instead of creating new functions:

const compareGuesses = (user, guess,computerGuess) => { 
    let userScore;
      if (user > guess) { userScore = user - guess; }    
      else { userScore = guess - user; }
    let compScore;
      if (computerGuess > guess) { compScore = computerGuess - guess; } 
      else { compScore = guess - computerGuess; }
     if (compScore < userScore) {return false}
     else {return true}  };

console.log(compareGuesses(1, 1, 5));
shorter version
const compareGuesses = (user, guess,computerGuess) => { 
    const userScore = (user > guess) ? user - guess : guess - user;
    const compScore = (computerGuess > guess) ? computerGuess - guess : guess - computerGuess;
    return !(compScore < userScore);

Thank you so much! You are a life saver! I didn’t realize I was supposed to call those functions and I’ve run into this problem before and never solved it. I was trying to avoid using the Math.abs because I wanted to try to figure it out with my own logic. I truly appreciate it!!