A multiple-choice quiz that runs entirely from one array. Answer, submit, move to the next question, and get a score at the end.
Stack#
Plain HTML, CSS and JavaScript. No framework, no router, no build step, no dependencies. Deployed to GitHub Pages.
Questions are data, not markup#
Every question is an object with the text, four options and the key of the correct answer:
const quizData = [
{
question: 'Which language runs in a web browser?',
a: 'Java',
b: 'C',
c: 'Python',
d: 'JavaScript',
correct: 'd',
},
// ...
]The markup is written once: four radio inputs with ids a through d.
loadQuizz() rewrites their labels from the current object. The radio ids
line up with the answer keys, so checking a submission is a single comparison:
if (answer === quizData[currentQuizz].correct) score++Because of this, you extend the quiz by appending an object, not by copy-pasting another block of HTML with its own handlers. The same approach works for any list-shaped interface.
Adding questions#
Append to quizData in script.js. Nothing else needs to change. The markup,
the scoring and the end screen stay as they are, and the end screen reads its
total from quizData.length.
Known limitations#
- No feedback per answer. You find out the score at the end and never learn which ones you got wrong.
- No going back.
currentQuizzonly increments. - The end screen replaces the container with
innerHTMLand restarts vialocation.reload()instead of resetting state. It works, but it throws away the page. alert()for the empty-answer case. Fine for a demo; an inline message would not block the thread or look like a browser error.
Running locally#
git clone https://github.com/Vette1123/Quizz-App.git
cd Quizz-App
# open index.html — no build, no server neededBuilt by Mohamed Gado