This commit is contained in:
Philippe Torrel
2026-09-28 09:42:41 +02:00
parent 8a2d979830
commit 80296c10d0
6 changed files with 89 additions and 16 deletions
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
@@ -25,6 +25,30 @@
</main>
<script>
'use strict';
// async function fetchUsers() {
const fetchUsers = async () => {
try {
const response = await fetch('https://dummyjson.com/users');
if (!response.ok) {
throw new Error(`HTTP-Fehler: ${response.status}`);
}
const data = await response.json(); // HTTP-Response Body
// console.log(data.users);
return data;
} catch (error) {
console.error('Benutzer konnten nicht geladen werden:', error);
}
};
fetchUsers().then((data) => {
data.users.forEach((user) => {
const { firstName = '', lastName = '', age } = user;
console.log(`name: ${firstName}, lastname: ${lastName}, age: ${age}\n`);
});
});
</script>
</body>
</html>