(10/10)

Pro Access Required

This is a premium lesson. Upgrade to Pro to unlock this interactive exercise and continue your learning journey.

📜JavaScript

Pet Simulator Game Loop

0 WPM
0% Accuracy
0:00 Time elapsed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class pet {
constructor(name) {
this.name = name;
this.hunger = 5;
}
feed() {
this.hunger = this.hunger - 1;
console.log(this.name + ' has been fed');
}
}
let my_pet = new pet('typy');
while (my_pet.hunger > 0) {
console.log(my_pet.name + 's hunger is ' + my_pet.hunger);
let choice = prompt('type feed or wait');
if (choice == 'feed') {
my_pet.feed();
}
}
console.log(my_pet.name + ' is full and happy');
0 / 480
Press This!
👇
`~
1!
2@
3#
4$
5%
6^
7&
8*
9(
0)
-_
=+
Q
W
E
R
T
Y
U
I
O
P
[{
]}
\|
A
S
D
F
G
H
J
K
L
;:
'"
Z
X
C
V
B
N
M
,<
.>
/?
Thumb
Index
Middle
Ring
Pinky