var myApp = angular.module("myApp", ["firebase"]);

/*if(game.end === true){
	$scope.push();
}

var list = $firebaseArray(ref);
list.$add({ foo: "bar" }).then(function(ref) {
  var id = ref.key();
  console.log("added score with id " + id);
  list.$indexFor(id); // returns location in the array
});*/


// AngularJS
$scope.authObj.$onAuth(function(authData) {
	var scoreX = rootRef.child("users").child(authData.uid)
  if (authData) {
    console.log(authData.uid +" "+  scoreX);
  } else {
    console.log("Logged out");
  }
});



//Use to call back user data
 rootRef.child('users').child(authData.uid).once('value', function(snapshot) {
   if (snapshot.val() === null) {
       console.log("No Users")
   } else {

       console.log(snapshot.val())
       window.alert(snapshot.val())
       //document.write(snapshot.val())
   }
});

// Using an event listener to trigger  this
rootRef.child('users').child(authData.uid/* username */).once('value', function(snapshot) {
   if (snapshot.val() === null) {
       console.log("No Users")
   } else {

       console.log(snapshot.val())
       //window.alert(snapshot.val())
       //document.write(snapshot.val())
   }
});


// Use to store player score on firebase

                    //var saveScore = function() {
                      var scoreRef = rootRef.child('users').child(authData.uid/* username */);
                      var gameEnd = true
                        if (gameEnd === true){
                          alert("conditional");
                              scoreRef.push({
                               //name for defined variable that stores score at end of game
                                "nick name": "Opizzasadder"
                                });
                                } else {
                                window.alert("Not Updated");
                                }
  
                    };

                   // }

// initial code
var saveScore = function() {
	var gameEnd = true
	var scoreRef = rootRef.child('users').child(authData.uid/* username */).once('value', function(snapshot);
		(gameEnd === true){
			scoreRef.update({
				//name for defined variable that stores score at end of game
				"nick name": "Opizza"
			};
		}
};



//call back to validat data save
dataRef.set("I'm writing data", function(error) {
  if (error) {
    alert("Data could not be saved." + error);
  } else {
    alert("Data saved successfully.");
  }
});
@@ -49,259 +49,8 @@
 );%0A%0A
-/*if(game.end === true)%7B%0A%09$scope.push();%0A%7D%0A%0Avar list = $firebaseArray(ref);%0Alist.$add(%7B foo: %22bar%22 %7D).then(function(ref) %7B%0A  var id = ref.key();%0A  console.log(%22added score with id %22 + id);%0A  list.$indexFor(id); // returns location in the array%0A%7D);*/%0A%0A
 %0A// 
@@ -500,24 +500,26 @@
 l())%0A       
+//
 window.alert
@@ -790,33 +790,93 @@
 s%22)%0A   %7D else %7B%0A
+%09%09var snap = snapshot.val();%0A        console.log(snap.name);
 %0A
-
        console.l
@@ -924,32 +924,32 @@
 snapshot.val())%0A
+
        //documen
@@ -963,33 +963,32 @@
 (snapshot.val())
-%0A
    %7D%0A%7D);%0A%0A%0A// Us

clean up code