-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathguessing_game.js
More file actions
35 lines (28 loc) · 923 Bytes
/
guessing_game.js
File metadata and controls
35 lines (28 loc) · 923 Bytes
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
module.exports = class GuessingGame {
constructor(channel, sessions) {
this.channel = channel;
this.sessions = sessions;
this.number = Math.round(Math.random() * 1000);
channel.send("I am thinking of a number between 0 and 1000...");
console.log("Number: " + this.number);
}
update(message) {
const channel = message.channel;
if (channel !== this.channel) {
return;
}
if (isNaN(message.content)) {
return;
}
const n = Number(message.content);
if (n === this.number) {
channel.send(`${message.author} guessed correct! The number was ${this.number}`);
return;
}
if (n > this.number) {
channel.send(`${n} guessed, but it is too big!`);
return;
}
channel.send(`${n} guessed, but it is too small!`);
}
};