tangway / flag-guessing-game-frontend

0 stars 0 forks source link

make checking function such that a click on any of the choices will check if answer is correct #3

Open tangway opened 6 months ago

tangway commented 6 months ago
tangway commented 5 months ago

realized through setting up tests for RTL #4 that i have not made the app show a visual change when user makes a selection so i implemented getStatus function which will display whether the answer is correct or wrong. it runs whenever the component gets re-rendered.

so the current flow is: user makes their selection -> checkAnswer(c) -> setCorrect runs -> state change automatically triggers re-render of react component -> triggers getStatus() which is inside the return of the component -> changes the STATUS msg

mermaid-diagram-2024-01-12-153328


const getStatus = () => {
    if (correct === true) return 'CORRECT';
    if (correct === null) return 'MAKE SELECTION';
    if (correct === false) return 'WRONG';
    return 'MAKE SELECTION';
  };

return (
    <>
      ...
      STATUS:
      {getStatus()}
      <div className="choices">
      ...
    </>