tangway / flag-guessing-game-frontend

0 stars 0 forks source link

keep score for the user #8

Open tangway opened 5 months ago

tangway commented 5 months ago

a very simple solution to managing the score for now where setScore(score + 1) is added to the checkAnswer function and simple rendered


const [score, setScore] = useState(0);
...
const checkAnswer = userSelection => {
    if (!selectionMade) {
      if (userSelection === correctAnswer) {
        setCorrect(true);
        setScore(score + 1);
      } else {
        setCorrect(false);
      }

      setSelectionMade(true);
      setStartAnimation(true);
    }
  };
...
<div className="score">
  Score: {score}/{questions.length}
</div>