-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
104 lines (93 loc) · 4.17 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
98
99
100
101
102
103
104
'use strict';
const inquirer = require('inquirer');
let numWrongAnswers = 0;
let numTotalWrongAnswers = 0;
let startTime;
const getRandomFromArray = genericResponses =>
genericResponses[Math.floor(Math.random() * genericResponses.length)];
const genericResponses = [
'Nope...have you considered asking Google for help?',
"Wrong...I don't know how to help you anymore",
"I don't think so...try harder",
"Correct!...oh no, it's actually wrong",
"No! that's not it",
'Unfortunately not :/ any other ideas?',
'Close!...but no cigar',
"I think you're on to something...or not...who knows!?!",
'NOT!...you could just give up...'
];
function getQuestion({ message, answer, responses, index }) {
responses = responses || [];
return {
type: 'input',
name: `question-${index}`,
message: message,
validate: function(value) {
const isCorrect =
typeof answer === 'function'
? !!answer(value)
: value.toLowerCase() === answer.toLowerCase();
if (isCorrect) {
numWrongAnswers = 0;
return true;
}
const response = responses[numWrongAnswers];
responses = responses || [];
if (value) {
numWrongAnswers++;
}
numTotalWrongAnswers++;
return response || getRandomFromArray(genericResponses);
}
};
}
module.exports = steps => {
const startTime = Date.now();
const questions = steps.map((step, index) => getQuestion(step, index));
console.log('----------------------------------------------------------');
console.log('');
console.log('GET READY!!!');
console.log('');
console.log('These are the rules');
console.log(
' - The faster you complete the adventure, the higher your score will be.'
);
console.log(
' - Every time you answer a question incorrectly, it will cost you 10 seconds!'
);
console.log('');
console.log('----------------------------------------------------------');
questions.unshift(
getQuestion({
message: 'Type "I suck" to begin',
answer: 'I suck',
index: -1
})
);
inquirer.prompt(questions).then(answers => {
const timePenalty = numTotalWrongAnswers * 10;
const endTime = Date.now();
var timeDiff = (Math.abs(endTime - startTime) / 1000).toFixed(2);
console.log('----------------------------------------------------------');
console.log('Great Success!');
console.log(`You completed the game ${timeDiff} seconds`);
console.log(`You had ${numTotalWrongAnswers} wrong answer`);
console.log(`That's a penalty of ${timePenalty} seconds`);
console.log(
`Leaving you with a total time of ${timeDiff + timePenalty} seconds`
);
console.log('----------------------------------------------------------');
console.log(`
▄████ ▄▄▄ ███▄ ▄███▓▓█████ ▒█████ ██▒ █▓▓█████ ██▀███
██▒ ▀█▒▒████▄ ▓██▒▀█▀ ██▒▓█ ▀ ▒██▒ ██▒▓██░ █▒▓█ ▀ ▓██ ▒ ██▒
▒██░▄▄▄░▒██ ▀█▄ ▓██ ▓██░▒███ ▒██░ ██▒ ▓██ █▒░▒███ ▓██ ░▄█ ▒
░▓█ ██▓░██▄▄▄▄██ ▒██ ▒██ ▒▓█ ▄ ▒██ ██░ ▒██ █░░▒▓█ ▄ ▒██▀▀█▄
░▒▓███▀▒ ▓█ ▓██▒▒██▒ ░██▒░▒████▒ ░ ████▓▒░ ▒▀█░ ░▒████▒░██▓ ▒██▒
░▒ ▒ ▒▒ ▓▒█░░ ▒░ ░ ░░░ ▒░ ░ ░ ▒░▒░▒░ ░ ▐░ ░░ ▒░ ░░ ▒▓ ░▒▓░
░ ░ ▒ ▒▒ ░░ ░ ░ ░ ░ ░ ░ ▒ ▒░ ░ ░░ ░ ░ ░ ░▒ ░ ▒░
░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
░
`);
});
};