-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
68 lines (57 loc) · 2.41 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env node
import inquirer from 'inquirer';
import chlak from "chalk";
import chalkanimation from "chalk-animation";
console.log((`
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
( D | E | V | E | L | O | P ) ( B | Y ) ( S | E | N | S | E | I )
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
`)
);
interface QuestionInterface{
question:string;
a:string|number|boolean,
b:string|number|boolean,
c:string|number|boolean,
d:string|number|boolean;
correct:string[];
}
interface quizInputInterface{
name:string,
type:string,
choices?:string[],
default?:string;
}
const quizInput:quizInputInterface[]=[{name:'question',type:"input"},{name:'a',type:"input"},{name:'b',type:"input"},{name:'c',type:"input"},{name:'d',type:"input"},{name:'correct',type:"checkbox",choices:['a','b','c','d'],default:'c'}];
let questionList:QuestionInterface[]=[];
async function Quiz() {
let studentMarks=0;
let totalQuestions=Number((await inquirer.prompt({name:"TotalQuestions",type:"number"})).TotalQuestions);
for(let i=0;i<totalQuestions;i++){
let tempQuestion:QuestionInterface=(await inquirer.prompt(quizInput).then((answer)=>{return answer}));
/*console.log(tempQuestion);
questionList[i].question=tempQuestion.question;
questionList[i].a=tempQuestion.a;
questionList[i].b=tempQuestion.b;
questionList[i].c=tempQuestion.c;
questionList[i].d=tempQuestion.d;
questionList[i].correct=tempQuestion.correct;*/
questionList.push(tempQuestion);
console.clear();
}
console.clear();
for(let i=0;i<questionList.length;i++){
console.log(`Question : ${questionList[i].question}\n`);
console.log(`${questionList[i].a}\n${questionList[i].b}\n${questionList[i].c}\n${questionList[i].d}\n`);
let studentResponse:string[]=(await inquirer.prompt({name:"answers",type:"checkbox",choices:['a','b','c','d']})).answers;
studentResponse.sort();
questionList[i].correct.sort();
if(JSON.stringify(studentResponse)===JSON.stringify(questionList[i].correct)){
studentMarks++;
}
console.clear();
}
console.log(`You gained ${studentMarks}/${questionList.length}, ${(studentMarks/questionList.length)*100}%\n`)
}
Quiz();