A library to create dynamic quizzes.
npm i quizzify
<script src="https://cdn.jsdelivr.net/npm/quizzify@1.0.0/dist/quizzify.umd.js" type="module"></script>
property | types | Description |
---|---|---|
question | string | A question statement |
type | number | string | The answer type |
input | "text" | "number" | "radio" | The type of input |
answer? | number | string | number [ ] | string [ ] | The real answer |
answers | number | string | number [ ] | string [ ] | The possibles answers |
reply? | number | string | number [ ] | string [ ] | Answer replied by the user |
error? | number | Max error allowed for numerical replies |
score? | number | A score value for the question |
const question = {
question: 'some question statement',
type: "number", // type of question
input: "text", // type of answer input
answer: 2.20, // (optional) real answer
answers: [-2.20, 2.20, 1.10, -1.10] // possible answers
}
// server.js
const question1 = {
question: "How much is 2 + 2.5?",
type: "number",
entry: "input",
value: 4.5,
error: 10 // - + error percentage allowed
}
const question2 = {
question: "What of next numbers is prime?",
type: "string",
answers: [
"9",
"10",
"11",
"12"
]
}
const questions = [question1, question2]
// client.js
const API = 'https://someapi.com';
const questions = await fetch(API);
const quiz = new Quiz(questions);
quiz.start();
// for response;
const currentAnswer = someInput.value;
quiz.setCurrentAnswer(currentAnswer);
// end quiz
quiz.end();
const myAnswers = quiz.getAnswers();
const question = {
question: "if A = B + C then:",
value: ["B - A = - C", "A - C = B"],
type: "radio",
answers: [
"B - A = - C", // 1
"C - A = B", // 2
"A - C = B", // 3
"None" // 4
]
}
const question = "The temperature value is ${temperature} °C"
const variables = { temperature: 12.0 }
quiz.parseTemplate(question, variables);
>> The temperature value is 12.0 °C
// Define some variables
const variables = {
"speed": {
type: "number",
value: 0,
default: 0,
min: -20,
max: 30
},
"angle": {
type: "number",
value: 0,
default: 0,
min: 0,
max: 360
},
"color": {
type: "string",
value: "",
default: "red",
}
}
const quiz = new Quiz(questions, variables);
MIT