Home > Mobile >  API Fetch not pulling data
API Fetch not pulling data

Time:12-06

all this is my first attempt at trying to write my first API fetch and I keep getting the following error Uncaught (in promise) ReferenceError response is not defined at getISS (index.html:19) These are the 2 lines that seem to be causing the problem:

const data = await response.json();
getISS();

Not entirely sure how to fix this issue.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    </head>
    <title> API Test </title>
    <body>
    
        <h1>Where is the ISS? </h1>
        
        <p>Latitude: <span id="lat"></span><br />
        Longitude: <span id="lon"></span>

        <script>
        const iss_url = 'https://api.wheretheiss.at/v1/satellites/25544';
        async function getISS() {
        const respone = await fetch(iss_url);
        **const data = await response.json();**
        const { latitude, longitude } = data;
            
        document.getElementById('lat').textContent = latitude;
        document.getElementById('lon').textContent = longitude;
        }
        
        **getISS();**
        
        </script>
    </body>
</html>

CodePudding user response:

Looks like you have a typo at const respone = await fetch(iss_url); should be response not respone.

  • Related