-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-3.html
More file actions
112 lines (101 loc) · 3.1 KB
/
Copy pathtask-3.html
File metadata and controls
112 lines (101 loc) · 3.1 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Quiz & API Demo</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
background-color: #9d9a9ad0;
color: #333;
text-align: center;
padding: 20px;
}
h1 {
margin-bottom: 20px;
}
/* Carousel Section */
.carousel {
max-width: 400px;
margin: 20px auto;
position: relative;
}
.carousel img {
width: 100%;
border-radius: 10px;
}
.carousel button {
position: absolute;
top: 50%;
transform: translateY(-50%);
background: rgba(0, 0, 0, 0.5);
color: white;
border: none;
padding: 10px;
cursor: pointer;
}
.prev { left: 10px; }
.next { right: 10px; }
/* API Section */
.joke {
background: #fff;
padding: 20px;
margin: 20px auto;
border-radius: 8px;
max-width: 500px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
/* Responsive Design */
@media (max-width: 600px) {
body {
padding: 10px;
}
.carousel {
max-width: 90%;
}
h1 {
font-size: 1.5rem;
}
}
</style>
</head>
<body>
<h1>Take a Joke</h1>
<!-- Image Carousel -->
<div class="carousel">
<img id="carousel-image" src="https://picsum.photos/400/250?random=1" alt="Image Carousel">
<button class="prev" onclick="changeImage(-1)">❮</button>
<button class="next" onclick="changeImage(1)">❯</button>
</div>
<!-- API Data (Joke) -->
<div class="joke">
<h2>Random Joke</h2>
<p id="joke-text">Loading joke...</p>
<button onclick="fetchJoke()">Get Another Joke</button>
</div>
<script>
// Carousel Functionality
let currentImage = 1;
function changeImage(direction) {
currentImage += direction;
if (currentImage > 5) currentImage = 1;
if (currentImage < 1) currentImage = 5;
document.getElementById('carousel-image').src = `https://picsum.photos/400/250?random=${currentImage}`;
}
// API Fetch Functionality
async function fetchJoke() {
const response = await fetch('https://official-joke-api.appspot.com/random_joke');
const data = await response.json();
document.getElementById('joke-text').textContent = `${data.setup} - ${data.punchline}`;
}
// Fetch a joke when the page loads
fetchJoke();
</script>
</body>
</html>