title: Firebase : First Argument contains undefined in property
body: <p>In my webpage I am trying to do a query from one firebase db and an update on another firebase db.</p>
  
  <p>The issue is when I try to do an update on the second database I get an error saying that the property is undefined. </p>
  
  <p>I have put several console log and I am sure they contain a numeric value so I am not sure why firebase is complaining that the property is undefined.</p>
  
  <p>My HTML Page</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;
      Firebase Test
      &lt;/title&gt;
      &lt;/head&gt;
      &lt;style&gt;
      .alright
      {
          text-align: left;
          border: 1px solid black;
          border-collapse: collapse;
      }
      &lt;/style&gt;
      &lt;body&gt;
  
  
  &lt;input type="button" value="SHUFFLE" onClick="window.location.reload()"&gt;
  
  &lt;table class="alright"&gt;
  &lt;tr&gt;
  &lt;th&gt;&lt;h1&gt;Niyant&lt;/h1&gt;&lt;/th&gt;
  &lt;th&gt;&lt;h1&gt;Varun&lt;/h1&gt;&lt;/th&gt;
  &lt;/tr&gt;
  
  &lt;!--&lt;tr&gt;
  &lt;th&gt;&lt;h1 id="niyantscoretag"&gt;&lt;/h1&gt;&lt;/th&gt;
  &lt;th&gt;&lt;h1 id="varunscoretag"&gt;&lt;/h1&gt;&lt;/th&gt;
  &lt;/tr&gt;--&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;h2 id="ns"&gt;0&lt;/td&gt;
  &lt;td&gt;&lt;h2 id="vs"&gt;0&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;h3 id="nrank"&gt;0&lt;/td&gt;
  &lt;td&gt;&lt;h3 id="vrank"&gt;0&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;img id="imgtag1"/&gt;&lt;/td&gt;
  &lt;td&gt;&lt;img id="imgtag2"/&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;h2&gt;Winner is&lt;/h2&gt;&lt;/td&gt;
  &lt;td&gt;&lt;img id="imgtag3"/&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
  
      &lt;script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"&gt;&lt;/script&gt;
      &lt;script&gt;
  
        var config = {
          apiKey: "AIzaSyAXpEHm1uLfRLS-6QCun1iVioquEmpmbAI",
          authDomain: "helloworld-3c2e7.firebaseapp.com",
          databaseURL: "https://helloworld-3c2e7.firebaseio.com",
          projectId: "helloworld-3c2e7",
          storageBucket: "helloworld-3c2e7.appspot.com",
          messagingSenderId: "103101977379"
        };
        firebase.initializeApp(config);
  
        var otherAppConfig = {
  
      apiKey: "AIzaSyC3UBiLaBJoW0vfY5xJgtFWV_zdKl9vfWo",
      authDomain: "scoringdev-b5ede.firebaseapp.com",
      databaseURL: "https://scoringdev-b5ede.firebaseio.com",
      projectId: "scoringdev-b5ede",
      storageBucket: "scoringdev-b5ede.appspot.com",
      messagingSenderId: "123331117443"
  
  };
  
  var database1 = firebase.initializeApp(config,"primary");
  var database1_database = database1.database();
  
  var database2 = firebase.initializeApp(otherAppConfig, "secondary");
  var database2_database = database2.database();
  
  
  /************HERE**********/
  var nscoref = database2_database.ref('Niyant/Score');
  var vscoref = database2_database.ref('Varun/Score');
  var vscore,nscore,vscoreincremented,nscoreincremented;
  
  nscoref.on('value', 
                  function(snapshot){
  
  
                                          nscore = snapshot.val();
                                          nscoreincremented = nscore + 1;
                                          console.log("nscore = "+nscore);
                                          console.log("nscoreincremented = "+nscoreincremented);
  
                                     }
          );
  
  vscoref.on('value', 
                  function(snapshot){
  
  
  
                                          vscore = snapshot.val();
                                          vscoreincremented = vscore + 1;
                                          console.log("vscore = "+vscore);
                                          console.log("vscoreincremented = "+vscoreincremented);
  
                                     }
          );
  
  
  
  
  var URLPath1,URLPath2,nsv,vsv;
  
  
  var num1 = Math.floor(Math.random() * 100) + 1;
  var num2 = Math.floor(Math.random() * 100) + 1;
  
  if(num1 &lt; num2)
  {
      database2_database.ref('Niyant').set({Score: nscoreincremented});
  }
  else if(num1 &gt; num2)
  {
      database2_database.ref('Varun').set({Score: vscoreincremented});
  }
  
  
  var imgref1 = database1_database.ref(num1+'/Location');
  var imgref2 = database1_database.ref(num2+'/Location');
  var imgref1_name = database1_database.ref(num1+'/Name');
  var imgref2_name = database1_database.ref(num2+'/Name');
  
  
  imgref1.on('value', 
                  function(snapshot){
  
                                          URLPath1 = snapshot.val();
                                          console.log(URLPath1);
                                          console.log(snapshot.val());
  
                                          document.getElementById("imgtag1").src = URLPath1;
                                          document.getElementById("nrank").innerText = 'Rank '+num1;
                                          if(num1 &lt; num2)
                                          {
                                              document.getElementById("imgtag3").src = URLPath1;
  
  
                                          }
  
                                     }
          );
  
  imgref2.on('value', 
                  function(snapshot){
  
                                          URLPath2 = snapshot.val();
                                          console.log(URLPath2);
  
  
                                           document.getElementById("imgtag2").src = URLPath2;
                                           document.getElementById("vrank").innerText = 'Rank '+num2;
                                           if(num2 &lt; num1)
                                          {
                                              document.getElementById("imgtag3").src = URLPath2;
  
                                          }
                                    }
  
          );
  
  imgref1_name.on('value', 
                  function(snapshot){
  
                                          URLPath1_name = snapshot.val();
                                          console.log(URLPath1_name);
                                          console.log(snapshot.val());
  
                                          document.getElementById("ns").innerText = URLPath1_name;
  
  
                                     }
          );
  
  imgref2_name.on('value', 
                  function(snapshot){
  
                                          URLPath2_name = snapshot.val();
                                          console.log(URLPath2_name);
  
  
                                           document.getElementById("vs").innerText = URLPath2_name;
  
                                     }
          );
  
  
      &lt;/script&gt;
  
  
  
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>This is from the Chrome console.</p>
  
  <p><a href="https://i.stack.imgur.com/rgzlv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rgzlv.png" alt="enter image description here"></a></p>
  
  <p>The problematic updates are commented out with "***HERE****" in the source for reference.</p>
  
  <p>Can someone help me out here ?</p>