Log in from a computer to take this course

You'll need to log in from a computer to start Learn Intermediate JavaScript. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store
Learn

Great job making it this far!

In the previous exercise, we called the fetch() function to make a GET request to the Datamuse API endpoint. Then, you chained a .then() method and passed two callback functions as arguments — one to handle the promise if it resolves, and one to handle network errors if the promise is rejected.

In this exercise, we will chain another .then() method, which will allow us to take the information that was returned with the promise and manipulate the webpage! Note that if there is an error returns in the first .then() method, the second .then() method will not execute.

Instructions

1.

At the end of the .then() method, chain another .then() method.

As the first argument of our second .then() method, pass an anonymous arrow callback function that takes jsonResponse as its single parameter.

2.

Inside the callback function we just created, call the renderRawResponse() function and pass in jsonResponse as its argument. Run the code.

In the input field, type in a word and click the submit button.

If all went well, we should see an array of words that the Datamuse API responded with!

Note that you can find the renderRawResponse() function declaration in public/helperFunctions.js.

3.

Let’s format our response from the Datamuse API to look presentable on the webpage. To do this, we will use the renderResponse() function that’s been defined in public/helperFunctions.js.

Comment out renderRawResponse(jsonResponse). Then below, call renderResponse(jsonResponse).

Run your code.

Try the webpage again with another word!

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?