• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Creating a Quiz/Trivia page


New Coder
Hi, I’m pretty new to Javascript but I do know a bit HTML and CSS since before.

I try to build a webpage where I can add quizzes with different topics (Animals/Music/Technology etc) where a question will be presented along with 3-4 answer options. I want the user to be able to browse through different topics, select a specific quiz (for instance, Animal topic can contain “African Animals”, “Sea creatures” etc, and I want to be able to label the questions used with 1 or more labels to fall within these cathegories. The questions and alternatives should show for each question, with maybe an "Expand" button to reveal the answer for the question.

For the questions, I think I might need to have an array, which contains arrays with the questions, where I add the question as a variable and then the options as other variables. Then I could fetch the first array and get questions within it based on Topics etc.

I just need some input on how I build up the framework for the questions in the easiest way so I do right from the beginning since I don’t think my method is optimal. I will need to have a file/variable containing all questions, maybe already categorized, so that I have an array for all “Animal”-related questions, another array for “Technology” questions etc. I then want to be able to fetch random questions from the topics, depending on what the user selects.

Any input on how to build a good database for questions, with different topics, that then can be randomly selected from different categories, or selected based on a specific category, for the user to be able to see would be of immense help!

var quiz = {
"Animals": [
"id": 1,
"category": Animals
"question": "What animal is the biggest mammal on earth?",
"options": [
"a": "Rhino",
"b": "Elephant",
"c": "Giraffe",
"d": "Blue whale"
"answer": "Blue whale",
"id": 2,
"category": "Insects"
"question": "How many legs does a spider have?",
"options": [
"a": "6 legs",
"b": "12 legs",
"c": "8 legs"
"answer": "8 legs",
I would use multiple selects in HTML to find the preferred quiz. And a database (mySql) to store the questions and answers for the different categories, PHP to mix them up, and maybe pick out just a couple of them. The job of JS would be to link the two together, paste the quiz to the HTML page, and reveal the correct answers.
Top Bottom