This commit is contained in:
57
06_js-debug/uebungen/u06_error-benutzer/solution.html
Normal file
57
06_js-debug/uebungen/u06_error-benutzer/solution.html
Normal file
@@ -0,0 +1,57 @@
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Übung 6: Benutzer erstellen</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="container py-5">
|
||||
<h1>Übung 6: Benutzer erstellen</h1>
|
||||
</div>
|
||||
</main>
|
||||
<script>
|
||||
'use strict';
|
||||
// Klammer zu hinzugefügt
|
||||
function createUser(name, email, age) {
|
||||
return {
|
||||
name,
|
||||
email,
|
||||
age,
|
||||
greet() {
|
||||
console.log(`Hello, ${this.name}!`);
|
||||
},
|
||||
updateEmail(newEmail) {
|
||||
this.email = newEmail;
|
||||
console.log(`Email updated to ${this.email}`);
|
||||
},
|
||||
displayAge() {
|
||||
console.log(`Age is ${this.age}`);
|
||||
},
|
||||
}; //geschweifte Klammer zu hinzugefügt
|
||||
}
|
||||
|
||||
const users = [
|
||||
createUser('Alice', 'alice@example.com', 30),
|
||||
createUser('Bob', 'bob@example.com', 25),
|
||||
createUser('Charlie', 'charlie@example.com', 35),
|
||||
];
|
||||
|
||||
users.forEach((user) => {
|
||||
user.greet();
|
||||
user.updateEmail(`new_${user.email}`);
|
||||
});
|
||||
|
||||
console.log(users);
|
||||
|
||||
function calculateTotal(...numbers) {
|
||||
return numbers.reduce((a, b) => Number(a) + Number(b), 0);
|
||||
}
|
||||
|
||||
console.log('Total:', calculateTotal(10, 20, 30)); //Komma hinzugefügt
|
||||
console.log('Total:', calculateTotal()); //=> 0
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user