title: trying to use the response.json in a second function to filter a specific result
body: <pre class="lang-js prettyprint-override"><code>import fetch from &quot;node-fetch&quot;;
  
  const URL_API = `https://jsonmock.hackerrank.com/api/countries?`;
  async function getResponse() {
    let response = await fetch(URL_API, {
      method: &quot;GET&quot;,
      headers: {
        &quot;Content-type&quot;: &quot;application/json&quot;,
      },
    })
      .then((response) =&gt; {
        return response.json();
      })
      .then((data) =&gt; {
        console.log(data);
      })
      .catch((error) =&gt; {
        // handle error
        console.error(`The unknown error has occurred: ${error}`);
      });
  }
  
  getResponse();
  
  async function getCapitalCity(country) {
    const data = await response.json(); //error mentioned here
    for (let info in data) {
      console.log(info);
      if (info.name === country) {
        return info.capital;
      } else {
        return -1;
      }
    }
  }
  
  console.log(getCapitalCity(&quot;Afghanistan&quot;));
  </code></pre>
  <p>working on retrieving a json object.  I am trying to use the response object from getResponse() in getCapitalCity() based on country entered (string).  My problem is knowing how to use the response in the second function.  currently get a promise rejected reference error: response is not defined.  thank you in advance.</p>