UNIT 25 • STAGE 7 OF 7
A JavaScript Set that tracks and displays unique cards flipped
A Set is a special collection that only stores unique values. If you add the same value twice, it only appears once. This makes it perfect for tracking which cards have been flipped; you want to count each card only once, even if the user flips it back and forth multiple times.
Each card has a data-index attribute (0 through 15). When a card is clicked, you add its index to the Set. Because Set ignores duplicates, the count only increases when a new card is flipped for the first time.
Replace your hero section with this updated version that includes the progress bar elements:
Also add the CSS for the progress bar into your <style> block:
Replace your existing flip script with this version that also updates the progress counter:
new Set() creates an empty Set. It works like an array but enforces uniqueness.flippedSet.add(card.dataset.index) adds the card's index to the Set. If it is already there, nothing changes.flippedSet.size is the number of unique values in the Set, equivalent to array.length.Math.round((count / total) * 100) converts the fraction to a percentage, then rounds it to a whole number.fill.style.width = pct + '%' updates the progress bar width. The transition: width 0.4s in CSS makes it animate smoothly.Flip cards in the preview; the progress bar fills as you explore new words. The counter tracks each card only once, no matter how many times you flip it.
You have built a full language learning tool with 3D CSS animation, category filtering, and a progress tracker powered by JavaScript's Set object.