A quiz app is one of the best beginner projects because it touches everything: state, events, timers, and rendering. In this project you will build a psychology quiz — ten questions about how the mind works, with one correct answer each, a score at the end, and a short explanation for every answer so users actually learn something.
If you want to go deeper into the subject after building the app, these best psychology books for beginners are a good place to start — they cover the same ideas the quiz tests, in much more depth.
Start with your questions as data. Keeping questions in an array means the quiz logic never changes when you add new questions — you only edit the data.
<div id="quiz"></div>
<button id="next">Next</button>
<div id="score"></div>
const questions = [
{
q: 'What is the "priming effect" in psychology?',
options: ['A memory trick', 'Exposure to one stimulus influences the response to another', 'A type of dream', 'A learning disability'],
answer: 1,
why: 'Priming happens when an earlier stimulus quietly shapes how you respond to the next one.'
},
{
q: 'Which part of the brain is most linked to forming new memories?',
options: ['Cerebellum', 'Hippocampus', 'Medulla', 'Corpus callosum'],
answer: 1,
why: 'The hippocampus is central to turning short-term experiences into long-term memories.'
}
];
let current = 0, score = 0;
const quizEl = document.getElementById('quiz');
function render() {
const item = questions[current];
quizEl.innerHTML = `<h3>${item.q}</h3>` + item.options.map((opt, i) =>
`<button data-i="${i}">${opt}</button>`).join('');
quizEl.querySelectorAll('button').forEach(btn => btn.onclick = () => {
const picked = +btn.dataset.i;
if (picked === item.answer) score++;
quizEl.innerHTML += `<p>${picked === item.answer ? 'Correct!' : 'Not quite.'} ${item.why}</p>`;
});
}
document.getElementById('next').onclick = () => {
current++;
if (current < questions.length) render();
else document.getElementById('score').textContent = `Your score: ${score}/${questions.length}`;
};
render();
Add a timer per question, shuffle the options so the correct answer is not always in the same spot, and store the best score in localStorage. Each feature is one small function, and each one teaches you something real about state.
The quiz is also a reminder of how learning works: testing yourself beats re-reading. That is why the app shows the explanation after every answer — the moment of feedback is where the learning happens.
Top comments (0)