ahmedhomar / ahmed-calculator

0 stars 0 forks source link

Feedback #1

Open DanForder opened 2 years ago

DanForder commented 2 years ago

Site

Code

// your code
decimalButton.addEventListener("click", (e) => {
  decimalString = e.target.value;

  if(!currentString.includes('.')) {
    currentString += '.'
  } else{
    return currentString;
   }

});

// refactor this to reference a separate function
const handleDecimalPress = (e) => {
  decimalString = e.target.value;
  if (!currentString.includes('.')) {
    currentString += '.'
  } else {
    return currentString;
  }
}

decimalButton.addEventListener("click", handleDecimalPress);
// remove decimal string, it's already "."
// remove unused "e" parameter
// remove else statement
const handleDecimalPress = () => {
  if (!currentString.includes('.')) {
    currentString += '.'
  }
}

decimalButton.addEventListener("click", handleDecimalPress);

Overall this is a great result Ahmed! For your game, I’d like to see you work on pulling out your logic into multiple functions. This is going to make it a lot easier for you/ others to follow your code without needing to read it line by line.

ahmedhomar commented 2 years ago

Thanks Dan. I was hoping to implement BEM but I ran out of time. I'll make sure to use it in the game project. Your feedback cleaning up my code is very helpful: thanks for the great examples.