-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
152 lines (130 loc) Β· 3.22 KB
/
app.js
File metadata and controls
152 lines (130 loc) Β· 3.22 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
var readlineSync = require("readline-sync");
const chalk = require("chalk");
var playerName = readlineSync.question(
chalk.yellowBright("π Namaste! Give me your name Please π\n=> ")
);
console.log(
chalk.bold.underline.cyanBright(
`\nπ Welcome! to ${chalk.yellow(
`"DO YOU KNOW ME"`
)} Quiz Game ${chalk.bold.yellowBright(playerName)}`
)
);
console.log(
chalk.magentaBright(
`\nRules:-\n1. Total number of Questions 5\n2. Each Question has 2 points for answering correct\n3. There is no negative marking for wrong answer`
)
);
if (
readlineSync.keyInYN(
chalk.bgWhite.black.bold(`\nLets Play!!! ${playerName} `)
)
) {
} else {
console.log(chalk.red.bold("\nπ π Oh no!! You exit from the game"));
process.exit();
}
var score = 0;
var play = (question, answer) => {
var playerAnswer = readlineSync.question(question);
if (playerAnswer.toUpperCase() === answer.toUpperCase()) {
console.log(chalk.green.bold("\nCongrats!! You are Correct π π"));
score = score + 2;
} else {
console.log(chalk.red.bold("\nOops!! You are Wrong π π"));
}
console.log(
chalk.bgMagentaBright.black.bold(
`Current score is: ${chalk.red.bold(score)} `
)
);
console.log(" ---------------- \n");
};
var questionSet = [
{
question: chalk.yellowBright("\nQ.1 Which State I am from?\n=> "),
answer: "West Bengal",
},
{
question: chalk.yellowBright("Q.2 Where do I currently live?\n=> "),
answer: "Chennai",
},
{
question: chalk.yellowBright(
"Q.3 What is my favourite Programming Language?\n=> "
),
answer: "Javascript",
},
{
question: chalk.yellowBright("Q.4 What is my favourite Web Series?\n=> "),
answer: "Breaking Bad",
},
{
question: chalk.yellowBright(
"Q.5 Who is my favourite Marvel Superhero?\n=> "
),
answer: "Iron Man",
},
];
for (var i = 0; i < questionSet.length; i++) {
var currentQuestion = questionSet[i];
play(currentQuestion.question, currentQuestion.answer);
}
console.log(
chalk.cyanBright.bold("Your final score is: ", chalk.red.bold(score))
);
if (score === 10) {
console.log(
chalk.yellowBright(
"\nπ€© π€© Wow!! You have answered all correct π π\nπ€ You are a close Friend π€"
)
);
} else if (score <= 4) {
console.log(chalk.yellowBright("\nπ You don't know much about me π"));
} else {
console.log(chalk.yellowBright("\nπ You are a good friend π"));
}
var leaderBoard = [
{
name: "Souvik",
score: 10,
},
{
name: "Rahul",
score: 10,
},
{
name: "Mahir",
score: 8,
},
{
name: "Sahil",
score: 5,
},
];
for (let i = 0; i < leaderBoard.length; i++) {
if (leaderBoard[i].score < score) {
console.log(
chalk.cyan.bold(
`\nπ Congrats! ${chalk.red.bold(
playerName
)} you have broken records π`
)
);
break;
}
}
console.log(
chalk.magentaBright(
`\n${chalk.red.bold(
"=>>"
)} Please sent a screenshort of your score, so that I can update the LeaderBoard.`
)
);
console.log(
chalk.yellow.bold(
`\n\nπ π Thanks for playing ${chalk.red.bold(
playerName
)} π Hope you enjoyed!!!`
)
);