-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
171 lines (151 loc) · 7.83 KB
/
app.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
'use strict';
//Here I want to alert the user of the instructions to use my game.
var userName = prompt('Hi there! Welcome to the About Me section of my page. Sorry for this prompt but we will be playing a little game.\n\nPlease follow along! What\'s your name?').toLowerCase();
document.getElementById('salutation').innerHTML = 'Hello ' + userName + ' !';
console.log('User\'s name is: ' + userName);
//Global Variable Assignment
var correctAnswers = 0;
var counter;
var favoriteContent = 0;
// Global functions/methods Assignment:
// function spitFavoriteContent (){
// favoriteContent = '';
// for (var i = 0; i < globalArray[4].length; i++){
// favoriteContent+= globalArray[4][i];
// }
// console.log(favoriteContent);
// return favoriteContent;
// }
//Global & userInput Array Assignment
var globalArray = [
['Can you guess what my favorite movies are? (Yes/No)','Can you guess what my favorite TV Shows are? (Yes/No)'],//question array = globalArray[0]
['yes','y','no','n'],//user input array = globalArray[1]
['Yes, I do love ' + favoriteContent[1] + ', and more!'],//answer Correct = globalArray[2]
['That\'s ok. You can learn what they are in a bit.','Sorry, you gotta answer yes or no. \n You Lose :,-('], //answer Incorrect array = globalArray[3] //[0] = No // [1] = else
[document.getElementsByTagName('ol')[0].textContent, document.getElementsByTagName('ol')[1].textContent,document.getElementsByTagName('ol')[2].textContent, document.getElementsByTagName('ol')[3].textContent], // globalArray[4] = favoriteContent
['US', 'ENGLAND', 'FRANCE', 'BELGIUM', 'NETHERLAND', 'GERMANY','ITALY', 'HUNGARY', 'CZECH REPUBLIC', 'ISRAEL', 'CHINA', 'THAILAND', 'CAMBODIA', 'KOREA'] //globalArray[5] = countries
];
//Question 1
function questionOne(){
var response1 = prompt(globalArray[0][1]).toLowerCase();
console.log('Can the user guess my favorite movies: ' + response1);
if (response1 === globalArray[1][0] || response1 === globalArray[1][1]) {
alert('Yes, I do love ' + globalArray[4][0] + ', and more!');
correctAnswers += 1;
} else if (response1 === globalArray[1][2]|| response1 === globalArray[1][3]){
alert(globalArray[3][0]);
} else {
alert (globalArray[3][1]);
}
}
questionOne();
console.log(' User\'s Correct Answers:' + correctAnswers);
// Question 2
function questionTwo(){
var response2 = prompt(globalArray[0][1]).toLowerCase();
console.log('Can the user guess my favorite tv shows: ' + response2);
if (response2 === globalArray[1][0] || response2 === globalArray[1][1]) {
alert('Yes, I love ' + globalArray[4][1] + ', and more!');
correctAnswers += 1;
} else if (response2 === globalArray[1][2] || response2 === globalArray[1][3]){
alert(globalArray[3][0]);
} else {
alert (globalArray[3][1]);
}
}
questionTwo();
// // Question 3
function questionThree(){
var response3 = prompt('Can you guess what my favorite Books are? (Yes/No)').toLowerCase();
console.log('Can the user guess my favorite books: ' + response3);
if (response3 === globalArray[1][0] || response3 === globalArray[1][1]) {
alert('Yes, I love ' + globalArray[4][2] + ', and more!');
correctAnswers += 1;
} else if (response3 === globalArray[1][2] || response3 === globalArray[1][3]){
alert(globalArray[3][0]);
} else {
alert (globalArray[3][1]);
}
}
questionThree();
//
// // Question 4
function questionFour() {
var response4 = prompt('Can you guess what my favorite random stuff/media are? (Yes/No)').toLowerCase();
console.log('Can the user guess my favorite random stuff: ' + response4);
if (response4 === globalArray[1][0] || response4 === globalArray[1][1]) {
alert('Yes, I love Dungeons and Dragons (D&D) related things (i.e. books, blurbs, etc.), Critical Role -online D&D adventure (Twitch Show), Random/Useless information acquired by following "internet rabbit-holes", and more!');
correctAnswers += 1;
} else if (response4 === globalArray[1][2] || response4 === globalArray[1][3]){
alert(globalArray[3][0]);
} else {
alert (globalArray[3][1]);
}
}
questionFour();
//Question 5
function questionFive () {
var response5 = prompt('Can you tell me what your favorite things are?').toLowerCase();
console.log('Some of the user\'s favotire things: ' + response5);
if (typeof response5 === 'string') {
document.getElementById('userLikes').innerHTML = '<li id="salutation">' + userName + ' likes : ' + response5 + ' <--- Nice!' + '</li>';
} else {
alert('That\'s ok, you don\'t wanna share, I understand.');
}
}
questionFive();
//
// // As a developer, I want to add a sixth question to my guessing game that takes numeric input by prompting a user to guess a number (for instance, "What is my favorite number?" or "How many Pokémon did I catch yesterday?"), and indicates to the user whether the guess is 'too high' or 'too low', and gives the user exactly four opportunities to get the correct answer, so that my fancy programming skills are showcased.
// //Question 6
function questionSix() {
var response6 = 0;
counter = 0;
while (response6 !== 26 && counter < 4){
response6 = parseInt(prompt('Q: In how many hours does a chicken lay one egg? \n Hint: It\'s less than 30!\nYou have 4 tries!'));
console.log('userName thinks the answer is: ' + response6);
counter += 1;
if (response6 > 26){
alert('Your number it greater than the answer!');
} else if (response6 === 26) {
alert('You\'re right, chickens take ' + response6 + ' hours to lay one egg!');
correctAnswers += 1;
} else if (isNaN(response6)) {
alert('Hey! Don\'t be a smartass!');
} else {
alert('Your number is lesser than the answer!');
}
}
if (response6 !== 26){
alert('BTW chickens take 26 hours to lay one egg!');
}
}
questionSix();
// //
// // // As a developer, I want to add a seventh question to my guessing game that has multiple possible correct answers that are stored in an array. For instance, "Can you guess a state that I have lived in besides Washington?", so that even more of my programming skills are showcased. For now, I will structure this question so that the user has six tries to get a single correct answer, and upon using up those tries OR getting a correct answer, displays a message to the user indicating all of the possible correct answers.
// //Question 7
function questionSeven() {
var countries = ['US', 'ENGLAND', 'FRANCE', 'BELGIUM', 'NETHERLAND', 'GERMANY','ITALY', 'HUNGARY', 'CZECH REPUBLIC', 'ISRAEL', 'CHINA', 'THAILAND', 'CAMBODIA', 'KOREA'];
var responseCountries = 0;
var responseCountriesBreak = false;
counter = 0;
while(counter < 6 && responseCountriesBreak === false){
responseCountries = prompt('Can you guess the countries I have traveled to?\nYou have 6 tries.\nTip: Use the correct names').toUpperCase();
for (var i = 0; i < countries.length; i++) {
if(responseCountries === countries[i]) {
console.log(countries[i]);
responseCountriesBreak = true;
alert ('Hey, ' + userName + ' you guessed ' + correctAnswers + ' out of: 6 \n Here are the other places I have been: ' + countries);
correctAnswers += 1;
var showCountriesAsString = countries.join(' , ')
document.getElementById('salutation').innerHTML = 'Hey ' + userName + ' these are other places I have been to: ' + showCountriesAsString.toString();
if(responseCountries === !countries[i]){
alert ('Sorry ' + userName + ', you\'re wrong! \nTry again!');
}
}
}
counter += 1;
console.log(counter + '= counter');
}
}
questionSeven();
// As a developer, I want to keep a tally of the total number of correct answers given by the user, and at the end of the game, tell the user how well they did with a personalized custom message that includes the number of correct answers and also addresses the user by name, e.g. "You got 4 out of 7 questions correct, Bobbi! Better luck next time."