| Level Navigation: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18⚡ | 19 |
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.
Add conditional rendering to show a win message at 100 points.
score >= 100 && to conditionally show an <h1> elementApp.css, style the .win class:
position: absolute to center itleft: 50%; top: 50% for positioningtranslate: -50% -50% to perfectly center itNeed help with conditional rendering? Check out these snippets:
<div className='orchard-background' onClick={missTarget}>
<div className="apple-target" onClick={clickTarget} style={appleStyle}></div>
{score >= 100 && <h1 className="win">You Win!</h1>}
</div>
.win {
position: absolute;
background-color: green;
color: red;
left: 50%;
top: 50%;
translate: -50% -50%;
}
{score >= 100 && ...}Understanding the && operator:
condition && <Component /> works like: “If condition is true, render Component”Understanding CSS translate for centering:
left: 50% and top: 50% move the element’s top-left corner to the centertranslate: -50% -50% shifts the element back by half its own width and heighttransform: translate(-50%, -50%) syntaxLearn More: