JavaScript Requests II, 4. fetch() GET Requests III

So i’m at an impasse…

const getSuggestions = () => {
const wordQuery = inputField.value;
const endpoint = url + queryParams + wordQuery;
  fetch(endpoint).then(response => {
    if (response.ok) {
      return renderJsonResponse(response);

is my current code, I got to the part where it asked me to create an if conditional statement that would call renderJsonResponse(response). As you can see, I do so above…now when I run it, it tells me “Did you call renderJsonResponse(response) inside the conditional statement?” Any input on where i’m wrong?

why would you use return here?

1 Like

I’m confused; if I did not use a return on an if condition statement, wouldn’t it have given an error?

you do nothing with the response when you call getSuggestions();, so why return the rendereJsonResponse? The exercise seems to not appreciated the return keyword.

The exercise states (and I quote) " Inside the success callback function, create a conditional statement that checks if the ok property of the response object evaluates to a truthy value. If so, call the function renderJsonResponse() and pass in response as an argument. Then, run your code."

By entering in .then(response => {
if (response.ok) {
return renderJsonResponse(response); <— the code they say to enter in after the response.ok
Should it not allow me to continue? I’m not trying to be a smart*** here, just trying to fully understand why. Also, it’s difficult to tell where I went wrong because once the solution is provided it is for the entire exercise as opposed to the section I was coding in.

But nowhere it says to use return. if you look at the renderJsonResponse function, you see this function doesn’t return anything so there is no value in using return when calling renderJsonResponse

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.