-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (36 loc) · 1.15 KB
/
index.js
File metadata and controls
38 lines (36 loc) · 1.15 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
// Initialize Firebase
var config = {
apiKey: "xxx",
authDomain: "xxx",
databaseURL: "xxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx"
};
firebase.initializeApp(config);
// setting event handler
document.getElementById("startbutton").onclick = function(){
// firebaseへの書き込み
var nickname = document.getElementById("nickname").value;
var userref = firebase.database().ref('users').child(nickname);
userref.set({score: 0});
for (i=1; i<=15; i++) {
userref.child('q' + i).set({ans: ''});
}
// 画面遷移
document.getElementById("loginform").className = "nodisp";
document.getElementById("buttons").className = "";
};
var buttons = document.getElementsByClassName("answerbutton");
for (var elm of buttons){
elm.onclick = function(){
var buttonval = this.value;
// 現在の問題Noを取得
firebase.database().ref('qnow').once('value', function(snapshot){
var qnow = snapshot.val();
// 解答内容を書き込み
var nickname = document.getElementById("nickname").value;
firebase.database().ref('users').child(nickname).child('q' + qnow).set({ans: buttonval});
})
};
}