-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
98 lines (71 loc) · 2.27 KB
/
index.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
onst chalk = require('chalk');
var readlineSync = require('readline-sync');
var score = 0;
// data of high score
var highScores = [
{
name: "Neha",
score: 3,
},
{
name: "Abhay",
score: 2,
},
]
// array of objects
var questions = [
{
question: "Which of the following is a primary color.\n"+chalk.magentaBright("Pink\n")+chalk.green("Green\n")+chalk.red("Red\n"),
answer: "Red",
},
{
question: "Which of the following is a secondary color\n"+chalk.magentaBright("Pink\n")+chalk.green("Green\n")+chalk.yellow("Yellow\n"),
answer: "Green",
},
{
question: "What does "+ chalk.red("red ")+"and "+chalk.yellow("yellow ")+ "gives you? \n "+chalk.magentaBright("Pink\n")+chalk.rgb(255, 136, 0)("Orange\n")+chalk.yellow("Yellow\n"),
answer: "Orange",
},
{
question: "What does "+ chalk.yellow("yellow ")+"and "+chalk.green("blue ")+ "gives you? \n "+chalk.magentaBright("Pink\n")+chalk.green("Green\n")+chalk.yellow("Yellow\n"),
answer: "Green",
},
{
question: "What does "+ chalk.red("red ")+"and "+chalk.blue("blue ")+ "gives you? \n "+chalk.magentaBright("Pink\n")+chalk.rgb(152,98,253)("Violet\n")+chalk.yellow("Yellow\n"),
answer: "Violet",
},
];
function welcome() {
console.log("Welcome to KNOW YOUR COLORS" );
console.log("\n----------------------------------------\n");
console.log(chalk.bold.redBright( "Let's test your Knowledge about colors!"));
var userName=readlineSync.question("What should I call you?");
console.log("Welcome " + userName );
console.log(" Note: Put answers as they are in the option, as they are case sensitive!");
console.log("Here you go!" );
}
function quiz(question, answer) {
var userAnswer = readlineSync.question(question);
if (userAnswer === answer) {
console.log("right!");
score = score + 1;
} else {
console.log("wrong!");
}
console.log("current score: ", score);
console.log("-------------")
}
function game() {
for (var i=0; i<questions.length; i++) {
var currentQuestion = questions[i];
quiz(currentQuestion.question, currentQuestion.answer)
}
}
function showScores() {
console.log("YAY! You SCORED: ", score);
console.log(chalk.red("Check out the high scores"));
highScores.map(score => console.log(score.name, " : ", score.score))
}
welcome();
game();
showScores();