-
11[Database] Create a database
Next! We have to create a database to store the data.
1.Go to https://firebase.google.com/
2.Log in and go to console.
3.Add Project
4.Fill it up!
-
12[Database] Settings
1.Go to real time database rules.
2. Change “.read” and “.write” to true
This allows for reading and writing of data in the database!
-
13[Database] Create your first dataset
Simply click on the “+” sign and key in your Name and value!
-
14[Function] Get all students answers
1. Declare a list
var qnalist = document.getElementById("QnA");
2. Reference to the child in the database
firebase.database().ref().child("Past Questions/").on("value", function(snapshot) { }
3. Run a for-each loop
snapshot.forEach(function(data) { });
4. Store the data into various variables
var key = Object.keys(snapshot.val())[ind]; var snap = snapshot.child(key).val(); //If the date matches fetch data if(snap.date==dateinput){ var ans = snap.answer; var metric = snap.metricNo; //Store data in a list var list = document.createElement("li"); list.appendChild(document.createTextNode(metric)); qnalist.appendChild(list); var listAns = document.createElement("dl"); //Append the list listAns.appendChild(document.createTextNode(ans)); qnalist.appendChild(listAns); } //Increase the index ind++; });
5. Manipulate the data for your own use!! You can fetch different variables all from your snapshots!
-
15[Function] Get absent students
*This function is similar to "Get all student answers"*
Create algorithm to check for absent students
Basically it scans through class list and check with the "students answers" data field to see if the student is present on the entered date.
Verification of date and metric:
if((snap.date==dateinputID)&&(snap.metricNo==snapshotID.child(id).val()))
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.