forked from marklreyes/The-Friendship-Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsheldon.js
93 lines (84 loc) · 3.69 KB
/
sheldon.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
/*
* the BiG BANG THEORY
* Season 2, Episode 13
* The Friendship Algorithm
* Originally made by marklreyes
* Forked by PiciAkk
*/
const readline = require('readline-sync');
var Sheldon = (function () {
var shareMeal = function () {
letsEat = readline.question('Would you like to share a meal? Yes or no?\n').toLowerCase()
if (letsEat == 'yes') {
excellent = console.log("Excellent. Let's dine together and begin our friendship!");
return excellent;
} else {
shareDrink();
}
};
var shareDrink = function () {
letsDrink = readline.question('Alright, do you enjoy a hot beverage? Yes or no?\n').toLowerCase()
if (letsDrink == 'yes') {
popChoices = readline.question('Excellent. Popular choices include tea, coffee, cocoa?\n').toLowerCase()
switch (popChoices) {
case "tea":
console.log("Let's have " + popChoices + "together and begin our friendship!");
break;
case "coffee":
console.log("Let's have " + popChoices + " together and begin our friendship!");
break;
case "cocoa":
console.log("Let's have " + popChoices + " together and begin our friendship!");
break;
default:
console.log("I'm sorry, I don't do " + popChoices + ". What about a recreational activity? I bet we share some common interests!");
shareInterest();
break;
}
} else {
console.log("What about a recreational activity? I bet we share some common interests!");
shareInterest();
}
};
var shareInterest = function () {
var sheldonsInterests = ["programming", "paintballing", "coding", "science", "videogames", "videogaming", "playing halo"];
//Create the replied interests and the array it will be assigned to.
var yourInterests;
//Sheldon won't agree with you, period.
if (sheldonsInterests.includes(yourInterests)) {
//This doesn't need to be here but wishful thinking doesn't hurt.
console.log("Why don't we do that together? Let's partake in " + yourInterests + " and begin our friendship!");
return
} else {
//Create the array that the interests will be assigned to.
var collectResponses = [];
//Howard's loop counter.
var n = 0;
while (n < 10) {
n++;
yourInterests = readline.question('Tell me an interest of yours!\n').toLowerCase()
//Update the resonse and store it into the collection
collectResponses.push(yourInterests);
if (sheldonsInterests.includes(yourInterests)){
console.log("Why don't we do that together? Let's partake in " + yourInterests + " and begin our friendship!");
return
} else {
console.log("Really, " + yourInterests + "?! I don't do " + yourInterests + ".");
}
if (n > 6) {
//Randomly choose the least objectionable interest.
//I don't know what goes on in Shelly's mind so let's randomly choose.
var shellysRandomChoice = collectResponses[Math.floor(Math.random() * collectResponses.length)];
console.log("Why don't we do that together? Let's partake in " + shellysRandomChoice + " and begin our friendship!");
break;
}
}
}
};
return {
ask: function () {
shareMeal();
}
};
})();
Sheldon.ask()