title: Why do I keep getting the error s is not defined?
body: <p>I'm working on a homework problem and it keeps returning the same error. Here is the problem 
  Write a function named "json_average" that takes a JSON formatted string as a parameter in the format of an array of objects where each object has keys "mass", "density", "temperature", and "velocity" and each key maps to a floating point number. This function should return the average "velocity" of all the objects in the array as a JSON string in the format {"velocity": }</p>
  
  <p>I tried switching things around like using let s = 0 and var = 0, either way it's still not working. Here is the code I tried. </p>
  
  <pre><code>function json_average(x) {
      let data = JSON.parse(x);
      var s = 0 ;
      var n = 0; 
      var a;
      for (let i of data) {
          a = i["velocity"];
          s = s + a ;
          n = n + 1 ;
      }
      let d = {"velocity" : (s/n)};
      return(JSON.stringify(d));
  }
  </code></pre>
  
  <p>When I submit the code this is what it returns. </p>
  
  <pre><code>`error on input ['[{"mass": 3.55, "density": 380.72, "velocity": 33.11, "temperature": 46.8}, {"mass": 91.37, "density": 572.04, "velocity": 64.43, "temperature": -0.13}, {"mass": 40.4, "density": 124.52, "velocity": 52.8, "temperature": 38.81}, {"mass": 68.92, "density": 326.77, "velocity": 31.64, "temperature": 43.71}, {"mass": 3.22, "density": 419.85, "velocity": 70.64, "temperature": 23.58}]']:` 
  ReferenceError: s is not defined
  </code></pre>