Commit 4a398c68 authored by Ferdinand Schimana's avatar Ferdinand Schimana
Browse files

Task 2 with async quiz

parent 27add742
No preview for this file type
export function delay(){
return new Promise(function(resolve){
setTimeout(resolve, 200)
})
}
\ No newline at end of file
// index.js
import {askQuestion, answerQuestion} from './quiz.js'
let rnd = Math.floor(Math.random() * Math.floor(5));
const question = askQuestion(rnd)
console.log(question)
let a= prompt("Enter answer")
const answer = answerQuestion(rnd, a)
console.log(answer ? 'correct' : 'incorrect')
\ No newline at end of file
async function displayQuiz(){
const question = await askQuestion()
let a= await prompt("Enter answer")
const answer = await answerQuestion(question, a)
console.log(answer ? 'correct' : 'incorrect')
}
displayQuiz()
\ No newline at end of file
export let questions=[
import {delay} from './delay.js'
let questions=[
{
"question" : "Wie nennt man ein Selfie, das nur die Schuhe zeigt?",
"correctAnswer" : "a",
......@@ -40,3 +42,8 @@ export let questions=[
"d" : "Sie Bekommen Schluckauf"
}
];
export async function getQuestions(){
await delay();
return questions
}
\ No newline at end of file
import {questions} from './questions.js'
import {getQuestions} from './questions.js'
export function askQuestion(e){
console.log(e);
console.log(questions[e].question);
console.log("a: "+questions[e].a);
console.log("b: "+questions[e].b);
console.log("c: "+questions[e].c);
console.log("d: "+questions[e].d);
export async function askQuestion(){
const questions = await getQuestions();
let rnd = Math.floor(Math.random() * Math.floor(5));
console.log(questions[rnd].question)
console.log("a: "+questions[rnd].a)
console.log("b: "+questions[rnd].b)
console.log("c: "+questions[rnd].c)
console.log("d: "+questions[rnd].d)
return questions[rnd]
}
export function answerQuestion(rnd, a){
if(questions[rnd].correctAnswer === a) return true
export async function answerQuestion(question, a){
if(question.correctAnswer === a) return true
else return false
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment