codex-lv3-may-2025

Level Navigation: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18⚡ 19

Level 10: Add Win Condition Message

User Story: As a player, I want to see a “You Win!” message when I reach 100 points so that I know I’ve completed the game.

What You’ll Do

Add conditional rendering to show a win message at 100 points.

Instructions

💡 Code Hints

Need help with conditional rendering? Check out these snippets:

Show Me: conditional rendering with &&
<div className='orchard-background' onClick={missTarget}>
  <div className="apple-target" onClick={clickTarget} style={appleStyle}></div>
  {score >= 100 && <h1 className="win">You Win!</h1>}
</div>
Show Me: win class CSS styling
.win {
  position: absolute;
  background-color: green;
  color: red;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
}

✅ Check

  1. Play the game and reach 100 points
  2. “You Win!” message should appear in the center
  3. The message should overlay the game board
  4. Both the apple AND the win message should be visible
  5. If message doesn’t appear:
    • Check the conditional: {score >= 100 && ...}
    • Verify you’ve reached 100 points

Understanding the && operator:

Understanding CSS translate for centering:

Learn More: