Build a slide carousel! Two buttons page through a fixed set of slides, and the carousel wraps around at both ends instead of stopping.
The slides are Mountains, Rivers, Forests and Deserts, in that order, and the carousel opens on the first one.
Render a <button class="prev">Prev</button> and a <button class="next">Next</button>. Next moves one slide forward and wraps from the last slide back to the first; Prev moves one slide back and wraps from the first slide to the last.
Render a <p class="slide"> holding the current slide name on its own, and a <p class="position"> whose text is exactly the human friendly position such as 2 of 4 — the position counts from 1, not from 0.
Finally render a <div class="dots"> holding one <span> per slide, each carrying data-index set to its zero-based index. The span for the current slide has the class dot active; every other span has just dot. Templates cannot compute a class inline, so map the classes in a getter.
Examples:
Initial render:
<button class="prev">Prev</button>
<button class="next">Next</button>
<p class="slide">Mountains</p>
<p class="position">1 of 4</p>
<div class="dots">
<span class="dot active" data-index="0"></span>
<span class="dot" data-index="1"></span>
<span class="dot" data-index="2"></span>
<span class="dot" data-index="3"></span>
</div>
Click Next -> <p class="slide">Rivers</p>
Click Next twice -> <p class="position">3 of 4</p>
Click Next four times -> <p class="slide">Mountains</p> (it wrapped all the way round)
Click Prev once -> the span carrying class active is the one with data-index 3