Last active
November 14, 2022 20:55
-
-
Save irwingb1979/a3bac78eb08e16b7d833fbd43360eea0 to your computer and use it in GitHub Desktop.
Async Await - Try Catch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const content = document.querySelector('#content'); | |
async function fetchUsers() { | |
try { | |
const users = await fetch('https://jsonplaceholder.typicode.com/users'); | |
const usersJson = await users.json(); | |
console.log(usersJson); | |
showHtml(usersJson); | |
} | |
catch(err) { | |
console.log(err); | |
console.log('Hubo un errror'); | |
} | |
} | |
fetchUsers(); | |
function showHtml(users) { | |
users.forEach(element => { | |
content.innerHTML += ` | |
<div class="user"> | |
<h3>${element.name}</h3> | |
<p>${element.username}</p> | |
<p>${element.email}</p> | |
</div> | |
` | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment