Skip to content

Magoninho/quiz-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quiz Generator

demo

Table of Contents

  1. Getting Started
    1. Installation
    2. Creating a Project
      1. Steps

Getting started

Installation

Include this line in your html:

<script src="https://cdn.jsdelivr.net/gh/Magoninho/quiz-generator@1.0/quiz-generator-lib/dist/Quiz.js"></script>

Creating a project

Steps

  1. Install

  2. Create a div that you want to insert the quiz

<div id="myQuizDiv">
</div>
  1. Create a script for setting up the quiz
<script>
let quiz = new Quiz();
</script>

Create a new quiz by instanciating a Quiz object somewhere.

  1. Add questions to your Quiz
// Shuffling options enabled
quiz.setShuffle(true);

/* Adding a question to the quiz
Args: 
- Question name (string);
- Options (array of strings)
- Right answer index (number): that's the index of the right answer in the options array
*/
quiz.addQuestion(
	"Question 1 (Shuffled)", [
		"Alternative 1",
		"Alternative 2",
		"Alternative 3 (correct answer)",
		"Alternative 4"
	],
	2 // Right Answer Index (Alternative 3)
);

// Shuffling options disabled
quiz.setShuffle(false);

quiz.addQuestion(
	"Question 2 (Not shuffled)", [
		"Alternative 1",
		"Alternative 2",
		"Alternative 3",
		"Alternative 4",
		"Alternative 5"
	],
	0
);
  1. Start the quiz on a selected div
// Selecting a div to place the quiz in
let myDiv = document.getElementById("myQuizDiv");

// Starting the quiz
// Tip: you can use this in a function so you can start the quiz by pressing a button for example
quiz.start(myDiv);
  1. You can also add sounds using quiz.addSounds()
// Adding sounds
quiz.addSounds(
	document.getElementById("audio-win"),
	document.getElementById("audio-wrong")
);

There are audios included in this example. Click here to see

About

A quiz generator made with TypeScript

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published