Create a fetchBill function. It should assign (link I have given in the script) 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.
Call the fetchBill function from inside startApp.
What I have tried:
I have written the following code, but I keep receiving a warning that I haven't declared the fechBill function as required and assigned a correct URL. And that I should check instructions!
Expand|Select|Wrap|Line Numbers
- <script>
- "use strict";
- const startApp = () => {
- };
- const displayCartTotal = ({results}) => results;
- const fetchBill = () => {
- const api = 'https://randomapi.com/006b08a801d82d0c9824dcfdfdfa3b3c';
- fetch(api)
- .then(res => {
- res = JSON.stringfy(res);
- return res.json()
- })
- .then(data => displayCartTotal(data))
- .catch(err => consoole.log(err))
- }
- </script>