-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10.html
More file actions
47 lines (42 loc) · 1.57 KB
/
Copy path10.html
File metadata and controls
47 lines (42 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random User Generating Application</title>
</head>
<body>
<h1>Random User Generator</h1>
<button id="generateButton">Generate Random User</button>
<div id="userContainer">
<img id="userImage" src="" alt="User">
<p id="userName"></p>
<p id="userEmail"></p>
</div>
<script>
const generateButton = document.getElementById("generateButton");
const userImage = document.getElementById("userImage");
const userName = document.getElementById("userName");
const userEmail = document.getElementById("userEmail");
generateButton.addEventListener("click", fetchRandomUser);
function fetchRandomUser() {
fetch("https://randomuser.me/api/")
.then(response => response.json())
.then(data => {
const user = data.results[0];
const firstName = user.name.first;
const lastName = user.name.last;
const email = user.email;
const imageUrl = user.picture.large;
userName.textContent = `${firstName} ${lastName}`;
userEmail.textContent = email;
userImage.src = imageUrl;
})
.catch(error => {
console.error("Error fetching data:", error);
});
}
fetchRandomUser();
</script>
</body>
</html>