0

Create a fetchBill function. It should assign randomapi.com/api/006b08a801d82d0c9824dcfdfdfa3b3c to an api variable. It should then use the browser's fetch function to make a HTTP request to api. Using an arrow function in a .then call to the fetch function, return the response after converting it to JSON. Using an arrow function in another .then call to the first one, take the converted JSON data in a data parameter and call displayCartTotalwith it. Make sure to handle errors that may occur, e.g by showing a warning message in the console.

I get error

You are not correctly using "fetchBill" to make a HTTP request, convert the response to JSON and then call "displayCartTotal" with the data. See instructions

const fetchBill = () => {
  const api = 'https://randomapi.com/api/006b08a801d82d0c9824dcfdfdfa3b3c'
  fetch(api)
    .then((res) =>
      return res.json())
    .then((data) =>
      return displayCartTotal(data))
    .catch((err) => console.error(err))
}
fetchBill()
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Speed
  • 3
  • 3
  • Is there a question here? For whom are the instructions? – mplungjan Jul 15 '19 at 21:45
  • 2
    Start by no using the return keyword when you do not have {} in the then – mplungjan Jul 15 '19 at 21:46
  • I made you a snippet - it is not complete – mplungjan Jul 15 '19 at 21:49
  • Create a fetchBill function. It should assign https://randomapi.com/api/006b08a801d82d0c9824dcfdfdfa3b3c to an api variable. It should then use the browser's fetch function to make a HTTP request to api. Using an arrow function in a .then call to the fetch function, return the response after converting it to JSON. Using an arrow function in another .then call to the first one, take the converted JSON data in a data parameter and call displayCartTotalwith it. Make sure to handle errors that may occur, e.g by showing a warning message in the console. This is the instruction for the code – Speed Jul 15 '19 at 21:50
  • Please visit the [help] to see what and [ask]. - I updated your question to be a proper question. I then answered it. I then found a dupe and closed it – mplungjan Jul 15 '19 at 21:52
  • Thank you, much appreciated – Speed Jul 15 '19 at 22:05

1 Answers1

0

Just remove the returns since you do not have {} in the body of the thens

See When should I use `return` in es6 Arrow Functions?

const displayCartTotal = (data => console.log(data))


const fetchBill = () => {
  const api = 'https://randomapi.com/api/006b08a801d82d0c9824dcfdfdfa3b3c'
  fetch(api)
    .then(res  => res.json())
    .then(data => displayCartTotal(data))
    .catch(err => console.error(err))
}
fetchBill()
mplungjan
  • 169,008
  • 28
  • 173
  • 236