diff --git a/.test-summary/TEST_SUMMARY.md b/.test-summary/TEST_SUMMARY.md new file mode 100644 index 000000000..a5f0d5725 --- /dev/null +++ b/.test-summary/TEST_SUMMARY.md @@ -0,0 +1,14 @@ +## Test Summary + +**Mentors**: For more information on how to review homework assignments, please refer to the [Review Guide](https://github.com/HackYourFuture/mentors/blob/main/assignment-support/review-guide.md). + +### 3-UsingAPIs - Week2 + +| Exercise | Passed | Failed | ESLint | +|-------------------|--------|--------|--------| +| ex1-programmerFun | 5 | - | ✓ | +| ex2-pokemonApp | 5 | - | ✓ | +| ex3-rollAnAce | 7 | - | ✓ | +| ex4-diceRace | 7 | - | ✓ | +| ex5-vscDebug | - | - | ✓ | +| ex6-browserDebug | - | - | ✓ | diff --git a/3-UsingAPIs/Week2/assignment/ex1-programmerFun/index.js b/3-UsingAPIs/Week2/assignment/ex1-programmerFun/index.js index a99ca177b..799657388 100644 --- a/3-UsingAPIs/Week2/assignment/ex1-programmerFun/index.js +++ b/3-UsingAPIs/Week2/assignment/ex1-programmerFun/index.js @@ -16,29 +16,34 @@ Full description at: https://github.com/HackYourFuture/Assignments/blob/main/3-U url with `.shx`. There is no server at the modified url, therefore this should result in a network (DNS) error. ------------------------------------------------------------------------------*/ -function requestData(url) { - // TODO return a promise using `fetch()` +async function requestData(url) { + const res = await fetch(url); + if (!res.ok) throw new Error(`HTTP error! Status: ${res.status}`); + return res.json(); } function renderImage(data) { - // TODO render the image to the DOM + const img = document.createElement('img'); + img.src = data.img; + document.body.appendChild(img); console.log(data); } function renderError(error) { - // TODO render the error to the DOM + const h1 = document.createElement('h1'); + h1.textContent = `Error: ${error?.message || error}`; + document.body.appendChild(h1); console.log(error); } -// TODO refactor with async/await and try/catch -function main() { - requestData('https://xkcd.now.sh/?comic=latest') - .then((data) => { - renderImage(data); - }) - .catch((error) => { + +async function main() { + try { + const data = await requestData('https://xkcd.now.sh/?comic=latest') + renderImage(data); + } catch (error) { renderError(error); - }); + } } window.addEventListener('load', main); diff --git a/3-UsingAPIs/Week2/assignment/ex2-pokemonApp/index.js b/3-UsingAPIs/Week2/assignment/ex2-pokemonApp/index.js index 262113997..7b3a55ecb 100644 --- a/3-UsingAPIs/Week2/assignment/ex2-pokemonApp/index.js +++ b/3-UsingAPIs/Week2/assignment/ex2-pokemonApp/index.js @@ -1,38 +1,88 @@ -/*------------------------------------------------------------------------------ -Full description at: https://github.com/HackYourFuture/Assignments/blob/main/3-UsingAPIs/Week2/README.md#exercise-2-gotta-catch-em-all +/* Exercise 2 – simple & functional */ -Complete the four functions provided in the starter `index.js` file: -`fetchData`: In the `fetchData` function, make use of `fetch` and its Promise - syntax in order to get the data from the public API. Errors (HTTP or network - errors) should be logged to the console. -`fetchAndPopulatePokemons`: Use `fetchData()` to load the pokemon data from the - public API and populate the `