Flashcards are the classic way to learn vocabulary, and building your own flashcard app teaches you arrays, shuffling, state, and DOM rendering. We will build one with plain JavaScript that flips cards, tracks what you know, and repeats the words you get wrong.
First, the data. Each card is just an object with a front and a back:
const cards = [
{ front: "Hello", back: "नमस्ते" },
{ front: "Thank you", back: "धन्यवाद" },
{ front: "Good morning", back: "सुप्रभात" },
{ front: "How are you?", back: "आप कैसे हैं?" },
];
Shuffle the deck so every session feels fresh:
function shuffle(array) {
const copy = [...array];
for (let i = copy.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[copy[i], copy[j]] = [copy[j], copy[i]];
}
return copy;
}
The app itself is three pieces of state: the shuffled deck, the current index, and whether the card is flipped. Rendering is one function:
let deck = shuffle(cards);
let index = 0;
let flipped = false;
const cardEl = document.getElementById("card");
function render() {
cardEl.textContent = flipped ? deck[index].back : deck[index].front;
}
cardEl.addEventListener("click", () => {
flipped = !flipped;
render();
});
document.getElementById("nextBtn").addEventListener("click", () => {
index = (index + 1) % deck.length;
flipped = false;
render();
});
Add a flip animation with CSS — a transform: rotateY(180deg) transition on the card makes it feel physical. Then add two buttons, "I knew this" and "Still learning". Cards marked "still learning" go back into the deck so they appear again; cards you know get removed. That one feature turns a slideshow into a real learning tool, because it implements spaced repetition in its simplest form.
Store progress in localStorage so the deck remembers which words are mastered between visits. And add a small form so the user can add their own words — suddenly the app works for any language, not just the four words you hardcoded.
Flashcards work best as one part of learning a language, not the whole thing. Pairing them with reading helps a lot — the best English speaking books for beginners give you sentences and stories where these same words appear in context, which is how vocabulary actually sticks.
Extensions to try next: categories (greetings, food, travel) with a filter, a daily goal counter, and a quiz mode that shows four options instead of flipping the card. Each one is a focused exercise in arrays and state.
Top comments (0)