In my web app, I want to create a classroom and add the data to my firebase database.
var fbclass = firebase.database().ref().child('Classes');
function classcreation(q) {
var usuid = generateId();
var myClasses={};
myClasses.TheClass = document.getElementById('classroomName').value;
myClasses.Teacher = user.displayName;
myClasses.TeacherEmail = user.email;
myClasses.ClassID = usuid;
fbclass.child(user.uid).set(myClasses);
}
function generateId(){
return 'xxxx-xxxx-xxxx'.replace(/[x]/g, function(){
return (Math.random() * 9 | 0 ).toString();
})
}
After submitting the button it will then store the data to the firebase
but the problem is, if I create another classroom with the same user, it will just update the TheClass[classname] and not create another classroom.
What's wrong with my code? What did I miss?