-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
208 lines (169 loc) · 4.36 KB
/
app.js
File metadata and controls
208 lines (169 loc) · 4.36 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
'use strict';
let userName = prompt('Hi, Could you please enter your name');
console.log(userName);
alert(userName + 'Welcome to my page');
// I will ask user 5 yes/no Q
let totalCorrectAnswers=0;
let q1=prompt('Do I have a car?');
switch(q1.toLowerCase()){
case 'yes':
case 'y':
alert('no I do not have one');
console.log('no I dont have any');
break;
case 'no':
case 'n':
alert('you are correct');
console.log('no I have not');
totalCorrectAnswers++;
break;
default:
console.log('please ask me again');
alert('please enter yes or no');
}
let q2=prompt('Do I like pasta ?');
switch(q1.toLowerCase()){
case 'yes':
case 'y' :
alert(' no I dont like it');
console.log('yes I like it');
totalCorrectAnswers++;
break;
case 'no':
case 'n':
alert('you are correct');
console.log('no I do not like it');
break;
default:
console.log('please ask me again');
alert('please enter yes or no');
}
let q3=prompt('Do I like reading newspaper?');
switch(q1.toLowerCase()){
case 'yes':
case 'y':
alert('no I do not');
console.log('yes I like reading newspaper');
break;
case 'no':
case 'n' :
alert('you are correct');
console.log('no I do not like reading newspaper');
totalCorrectAnswers++;
break;
default:
console.log('please ask me again');
alert('enter yes or no');
}
let q4=prompt('Do I like cooking ?');
switch(q1.toLowerCase()){
case 'yes':
case 'y' :
alert('no I do not');
console.log('yes I do');
totalCorrectAnswers++;
break;
case 'no':
case 'n':
alert('you are correct');
console.log('no I do not ');
default:
console.log('please ask me again');
alert('enter yes or no');
}
let q5=prompt('Do you think I like drawing?');
switch(q1.toLowerCase()){
case 'yes':
case 'y':
alert('no I do not');
console.log('yes I do');
totalCorrectAnswers++;
break;
case 'no':
case 'n':
alert('you are correct ');
console.log('no I do not');
default:
console.log('please ask me again');
alert('please enter yes or no');
}
// Q6
let question="Could you guess my age in years, you have four opportunities? ";
let q6=prompt(question);
let myAge = 35 ;
let status=false;
for (let i = 0; i < 3 ; i++){
if (q6 > 35 || q6 < 30) {
alert('Its too far, you should try again!');
console.log(i);
}
else if ( q6 >= 30 && q6 < 35) {
alert('Its too close, you should try again!');
console.log(i);
}
else if (q6 == 35)
{
alert('Great, its correct');
totalCorrectAnswers++;
status=true;
break;
}
q6=prompt(question);
}
if(!status)
alert("sorry you have took out you attempts , my age was 35")
//Q7
let top10=['red','white','blue'];
let favMovie;
let quesition="which of the next colors were the author's favorite \n,"+
"(you have to guess 1 movie each attemp) \n"+
"-red \n"+
"-purple \n"+
"-white \n"+
"-blue \n"+
"-orange \n"+
"-green \n"+
"-black \n"+
"-yellow"
favMovie=prompt(quesition);
let answerState=false;
let correctAnswer=0;
let gussing=0;
let indexNo=-1;
while(gussing < 5 && correctAnswer !=2)
{
for(var j = 0 ; j<top10.length;j++)
{
if(favMovie.toLowerCase()==top10[j])
{
answerState=true;
indexNo=j;
break;
}
else{
answerState=false
}
}
if(answerState)
{
alert(top10[j]+" is a correct answer");
console.log(j)
correctAnswer++;
alert(3-correctAnswer+" left to guess")
}
else{
alert(favMovie+" is a wrong answer")
alert(5-gussing+" attempts left to guess");
}
gussing++;
favMovie=prompt(quesition);
}
totalCorrectAnswers+=correctAnswer+1;
if(gussing>2)
{
alert(" you have completed all your attemps , hard luck")
}
else
alert("Good Job you have gussed all the correctly correctly")
alert(userName +" your total points are "+ totalCorrectAnswers+"\n"
+"hope we can see you in another game")