I cannot understand the helper functions in http requests lessons

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

const renderResponse = (res) => {

// handles if res is falsey




// in case res comes back as a blank array


responseField.innerHTML = "<p>Try again!</p><p>There were no suggestions found!</p>"



// creating an array to contain the HTML strings

let wordList =

// looping through the response and maxxing out at 10

for(let i = 0; i < Math.min(res.length, 10); i++){

// creating a list of words



// joins the array of HTML strings into one string

wordList = wordList.join("")

// manipulates responseField to render the modified response

responseField.innerHTML = <p>You might be interested in:</p><ol>${wordList}</ol>



// Renders response before it is modified

const renderRawResponse = (res) => {

// taking the first 10 words from res

let trimmedResponse = res.slice(0, 10)

//manipulates responseField to render the unformatted response

responseField.innerHTML = <text>${JSON.stringify(trimmedResponse)}</text>


// Renders the JSON that was returned when the Promise from fetch resolves.

const renderJsonResponse = (res) => {

// creating an empty object to store the JSON in key-value pairs

let rawJson = {}

for(let key in response){

rawJson[key] = response[key]


// converting JSON into a string and adding line breaks to make it easier to read

rawJson = JSON.stringify(rawJson).replace(/,/g, “, \n”)

// manipulates responseField to show the returned JSON.

responseField.innerHTML = <pre>${rawJson}</pre>