title: Issue structuring a promise in a loop
body: <p>I am struggling with getting this resolved, as I am new to Promises. </p>
  
  <p>I need to first read both the <code>Summative</code> and <code>Formative</code> from Firebase before I can determine the <code>StudentPlacement</code> </p>
  
  <p>The way the code below, provides <code>null</code> as the StudentPlacement <code>snapshot.val()</code>, as it is not waiting for the <code>x</code> and <code>y</code> values.</p>
  
  <pre><code>exports.boxScoresUpdate = functions.database.ref('/Tests/{id}/TestScores').onWrite(event =&gt; {
  
      let testScr = 0;
  
      for (let i = 1; i &lt;= section; i++) {
          //
          testScr += parseInt(nValue[i]);
  
          var xIndex = 0;
          var yIndex = 0;
  
  
          admin.database().ref('TestScores').child(data.key).child('Summative').child(i).once("value").then(x =&gt; {
  
              xIndex = x.val();
  
          });
  
          admin.database().ref('TestScores').child(data.key).child('Formative').child(i).once("value").then(y =&gt; { 
  
              yIndex = y.val();
  
          });
  
          admin.database().ref('StudentPlacement').child(data.key).child(xIndex + ":" + yIndex).once("value", snapshot =&gt; {
  
              // SnapShot
              console.log("Student Placement is: ", snapshot.val());
  
          });
  
      }
  
  }
  </code></pre>
  
  <p>Can anyone please help me structure the trigger!? </p>