Back to Projects
4.4 - Flashcard App (Solution)
“Run” to see new changes
✕
Look inside
Run
main.js
index.html
style.css
×
×
Run
const flashcards = [ { question: "What does HTML stand for?", answer: "HyperText Markup Language" }, { question: "What keyword is used to declare a variable in JavaScript?", answer: "let" }, { question: "What is the capital of Japan?", answer: "Tokyo" }, { question: "What symbol starts a comment in JavaScript?", answer: "//" }, { question: "What data type is used for true/false values?", answer: "boolean" } ]; let currentIndex = 0; const questionText = document.getElementById("questionText"); const answerInput = document.getElementById("answerInput"); const submitBtn = document.getElementById("submitBtn"); const feedback = document.getElementById("feedback"); const nextBtn = document.getElementById("nextBtn"); function showQuestion() { questionText.textContent = flashcards[currentIndex].question; answerInput.value = ""; feedback.textContent = ""; } submitBtn.onclick = function () { const userAnswer = answerInput.value.trim().toLowerCase(); const correctAnswer = flashcards[currentIndex].answer.toLowerCase(); if (userAnswer === correctAnswer) { feedback.textContent = "✅ Correct!"; feedback.style.color = "lightgreen"; } else { feedback.textContent = "❌ Try again."; feedback.style.color = "salmon"; } }; nextBtn.onclick = function () { currentIndex = (currentIndex + 1) % flashcards.length; showQuestion(); }; showQuestion();
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Flashcard Quiz</title> <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet" /> <link rel="stylesheet" href="style.css" /> </head> <body> <div class="container"> <h2>🧠 Flashcard Quiz Challenge</h2> <p id="questionText"></p> <input type="text" id="answerInput" placeholder="Type your answer here..." /> <button id="submitBtn">Submit Answer</button> <p id="feedback"></p> <button id="nextBtn">Next Question</button> </div> <script src="main.js"></script> </body> </html>
body { font-family: 'Poppins', sans-serif; background: linear-gradient(to right, #373b44, #4286f4); color: white; height: 100vh; margin: 0; display: flex; align-items: center; justify-content: center; } .container { background-color: #1e1e1e; padding: 40px; border-radius: 16px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6); text-align: center; max-width: 500px; width: 90%; border: 1px solid #ffffff22; } h2 { margin-top: 0; font-size: 26px; } input { padding: 10px; font-size: 16px; width: 80%; border-radius: 6px; border: none; margin-top: 10px; } button { font-size: 16px; padding: 10px 20px; margin: 15px 10px 10px 10px; border: none; border-radius: 8px; background-color: #61dafb; color: #1e1e1e; cursor: pointer; transition: background-color 0.3s, transform 0.2s; } button:hover { background-color: #4fc3f7; transform: scale(1.05); } #feedback { font-weight: 600; margin-top: 10px; }
Console
AI Tutor
Documentation
Ask AI Tutor
Click RUN to execute project