title: How to use if / else statement with a JSON fetch API response Javascript
body: <p>I have two working code snippets that I would like to link with <code>if</code>/<code>else</code> logic. The first part of the code receives a JSON response from a web API. <code>JSON.TEMPERATURE</code> is the key variable needed.</p>
  <pre><code>const fetch = require(&quot;node-fetch&quot;);
  
  const api_url = 'https://www.placeholder_URL.com/api/getTemperature'
  
  fetch(api_url)
    .then((response) =&gt; {
      return response.json();
    })
    .then((myJSON) =&gt; {
      console.log(myJSON.TEMPERATURE); // **This returns a number between 8 and 15**
    });
  </code></pre>
  <p>The second part of the code plays a MIDI note. In the case below, <code>note</code> # 60 which is the Middle C. C# would be <code>note</code> 61, D <code>note</code> 62 and so forth.</p>
  <pre><code>let easymidi = require(&quot;easymidi&quot;)
  let output = new easymidi.Output(&quot;mindiPort&quot;, true)
  
  let sendNote = (noteValue, duration) =&gt; {
      output.send(&quot;noteon&quot;, noteValue)
  
      setTimeout(()=&gt; {
          output.send(&quot;noteoff&quot;, noteValue)
      }, duration);
  }
  
  setInterval(() =&gt; {
      let noteValue = {
          note: 60,   // **need to change this number depending on JSON.TEMPERATURE**
          velocity: 100,
          channel: 1
      }
      sendNote(noteValue, 500)
  }, 2000);
  </code></pre>
  <p>What I am looking to achieve is an <code>if</code>/<code>else</code> where the note played is dependent on <code>JSON.TEMPERATURE</code>.</p>
  <p>Something like:</p>
  <p><code>if JSON.TEMPERATURE ==</code> 8, play <code>note</code> 60</p>
  <p><code>if JSON.TEMPERATURE ==</code> 9, play <code>note</code> 61</p>
  <p><code>else</code>, play note 55</p>
  <p>I would also like to run the API request every 5 seconds.</p>