-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
103 lines (87 loc) · 2.88 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Display</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #00B1D2FF;
margin: 0;
padding: 20px;
}
h2 {
color: #333;
text-align: center;
}
#productTable {
max-width: 800px;
margin: 0 auto;
border-collapse: collapse;
width: 100%;
}
#productTable th, #productTable td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
transition: background-color 0.3s, transform 0.3s;
}
#productTable th {
background-color: #8f8f8f;
color: #fff;
}
#productTable tbody tr:hover {
background-color: #e6e6e6;
transform: scale(1.05);
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
#productList {
background-color: #d1ffd1;
}
</style>
</head>
<body>
<h2 class="heading">Task 1</h2>
<table id="productTable">
<thead>
<tr>
<th>Title</th>
<th>Price</th>
<th>Popularity</th>
</tr>
</thead>
<tbody id="productList"></tbody>
</table>
<script>
async function fetchData() {
try {
const response = await fetch('https://s3.amazonaws.com/open-to-cors/assignment.json');
return response.json();
} catch (error) {
console.error('Error fetching or parsing data:', error);
}
}
async function displayData() {
const productList = document.getElementById('productList');
const data = await fetchData();
if (data && data.products) {
const products = data.products;
const productArray = Object.keys(products).map(key => ({
id: key,
...products[key]
}));
const sortedData = productArray.sort((a, b) => b.popularity - a.popularity);
sortedData.forEach(product => {
const row = document.createElement('tr');
row.innerHTML = `<td>${product.title}</td>
<td>$${product.price}</td>
<td>${product.popularity}</td>`;
productList.appendChild(row);
});
}
}
displayData();
</script>
</body>
</html>