forked from Kahoot-Clone/kahoot-clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
42 lines (39 loc) · 1.09 KB
/
functions.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
let players = [];
let questions = [{correctanswer:3}]
module.exports ={
sum: (num1, num2) => {
return num1 + num2
},
generatePin: () => {
let newPin = Math.floor(Math.random() * 9000, 10000)
return newPin;
},
addPlayer:(name, id) => {
let player = {
id: id, // this is now their socket id so they can pull their score to the player component using this
name: name,
score: 0,
qAnswered: false,
answeredCorrect: false
}
let newPlayers = [...players];
newPlayers.push(player);
players = newPlayers;
return players
},
submitAnswer:(name, answer) => {
let player = players.filter(player => player.name === name);
let updatedPlayers = players.filter(player => player.name !== name);
player[0].qAnswered = true;
answer === questions[0].correctanswer
?player[0].answeredCorrect = true
:player[0].answeredCorrect = false
players = updatedPlayers.push(player[0])
return players
},
handleNicknameInput: (e) => {
let nickname = ''
nickname = e
return nickname
}
}