Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 3 months ago

Frontend Quiz App using TailwindCSS

tailwind-css
P
Carlos Samuel•350
@Crtykwod
A solution to the Frontend Quiz app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

I'm most proud of how I implemented the timer functionality in the quiz application. For example, this part of the code made me proud:

export const setTimer = () => {
  const duration = getTimerDuration();
  if (!duration || !elements.timerCheck.checked) {
    elements.root.style.setProperty("--animate-timer-playstate", "paused");
    saveTimerSettings();
    return;
  };
  state.timerDuration = duration;
  elements.root.style.setProperty("--animate-timer-playstate", "running");
  elements.root.style.setProperty("--animate-timer-duration", `${state.timerDuration}s`);
  saveTimerSettings();
};

This implementation uses CSS variables and animations for the timer visualization rather than JavaScript intervals, which is more performant and smoother. I also implemented persistent timer and theme settings using localStorage, allowing users to maintain their preferences between sessions.

What challenges did you encounter, and how did you overcome them?

One of the most significant challenges I encountered was implementing the quiz selection and rendering system that could handle different quiz categories dynamically. The main difficulty was creating a structure that could load the appropriate quiz data based on user selection and render it correctly. I solved this by developing a modular approach using the quiz-data.js and quiz-renderer.js files:

import {createQuiz} from "./quiz-renderer.js";
export const quizTypes = {
  html: (quiz) => createQuiz(quiz),
  css: (quiz) => createQuiz(quiz),
  javascript: (quiz) => createQuiz(quiz),
  accessibility: (quiz) => createQuiz(quiz),
};

This approach allowed me to maintain a clean separation of concerns between data fetching, quiz creation, and rendering logic. The quiz selection handler in quiz-logic.js then ties everything together:

export const handleQuizSelection = (event) => {
  const button = event.target.closest(".menu__button");
  if (!button) return;

  state.currentQuiz = button.textContent.trim();
  updateHeader();

  const selectedQuiz = quizTypes[state.currentQuiz.toLowerCase()];
  const quiz = selectedQuiz
    ? selectedQuiz(getQuizData(state.currentQuiz))
    : null;

  quiz ? renderQuiz(quiz) : restoreMainMenu();
};

Another challenge was implementing the dark/light theme toggle that needed to work seamlessly with the rest of the UI. The theme switching functionality required careful consideration of accessibility and user preferences, ensuring that all UI elements remained visible and properly styled in both themes.

What specific areas of your project would you like help with?

I would love feedback on the following areas:

- Timer Implementation in Quiz App

The timer functionality in my quiz app has been challenging to implement correctly. Here's the relevant code from my timer.js file:

import {elements, quizElements} from "./elements.js";

export const setTimesUpEvent = () => {
  // This function is called when the quiz is rendered
  // I need help ensuring this properly handles the timer animation
  // and correctly triggers when time runs out
}

I'm particularly concerned about:

  1. How to properly sync the CSS animation with the JavaScript timer logic

  2. Ensuring the timer resets correctly between questions

  3. Handling edge cases when a user answers just as time runs out

- Quiz Selection and Rendering Logic

I'm also looking for feedback on my quiz selection and rendering approach:

export const handleQuizSelection = (event) => {
  const button = event.target.closest(".menu__button");
  if (!button) return;

  state.currentQuiz = button.textContent.trim();
  updateHeader();

  const selectedQuiz = quizTypes[state.currentQuiz.toLowerCase()];
  const quiz = selectedQuiz
    ? selectedQuiz(getQuizData(state.currentQuiz))
    : null;

  quiz ? renderQuiz(quiz) : restoreMainMenu();
};

Is this approach maintainable for adding new quiz types in the future? Should I be using a different pattern for handling the quiz selection and creation?

Code
Couldn’t fetch repository

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    Nishanth Venkatesan•1,030
    @nishanth1596
    Posted 3 months ago

    Hi @Crtykwod,

    Awesome work on this project! The timer feature is a great addition. 🎉

    I just noticed that the timer runs for the whole quiz instead of resetting for each question, which makes it a bit tricky to complete the quiz properly. I’m not too experienced with JS, but I think the timer might need to reset when moving to the next question. Maybe you could check that?

    Also, for better project organization, creating a separate repo for each project would be ideal. Branching is usually used for feature updates rather than separate projects.

    One more thing—since this wasn’t done in React, it might be better not to tag React for clarity.

    And if possible, adding a bit more margin to the theme switcher would make the UI even better!

    Great job overall! Looking forward to seeing more of your work. 🚀

    Marked as helpful

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SASS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub