{#if}
{#if} renders its body only when its condition holds. {:else if} adds another test and {:else} catches the rest; {/if} closes it. Each condition is one expression, written the same way as in braces.
{#if albums.length > 1}
<p>Pick one.</p>
{:else if albums.length === 1}
<p>Only one left.</p>
{:else}
<p>Nothing here.</p>
{/if}
A condition can also sit inside a quoted attribute, for a class that comes and goes: class="card {#if album.inPlaylist}is-added{/if}". {#unless} is the negated form, for when the else is the interesting half.
Your turn
Every card has an Add button, even for albums already in the playlist. Give the card three states instead:
- In the playlist: an "In playlist" badge,
<span class="badge">In playlist</span>, and no button. - One copy left (
album.stock === 1): a button that says "Add the last copy". - Otherwise: the Add button.
Then add a few albums and watch their cards change.