Help with Reviewing code

Hello!

So, I recently finished the project Number guesser, but I would like some feedback on my code and the way I write it. Some advice on formatting would be nice.

Here’s my code:

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

// Write your code below:
const generateTarget = () => {
  return Math.floor(Math.random() * 10)
}
const compareGuesses = (playerGeuss, computerGeuss, targetNumber) => {
  const playerCloseness = Math.abs(playerGeuss - targetNumber)
  const computerCloseness =  Math.abs(computerGeuss - targetNumber)
if(playerCloseness < computerCloseness || playerCloseness === computerCloseness){
  return true
}else{
  return false
}
}
const updateScore = winner => {
winner.toLowerCase()
if(winner === 'computer'){
  computerScore += 1
}else if(winner === 'human'){
  humanScore += 1
}
}
const advanceRound = () => {
  currentRoundNumber =+ 1
}


It looks good. The only formating I would HIGHLY recommend is indenting. How much is up to you. Normally it is 2 or 4 spaces or a single tab.

1 Like

While it of course is ultimately up to you, both the Google and AirBnB style guides for JS suggest you use two spaces so that’s what is probably best to use imo:

That said, the important thing is consistency, of course you can use whatever you wish, but be consistent across a code base (and do not mix spaces and tabs). But as always, that’s just my 2c :smile:

1 Like