Notes
![]() ![]() Notes - notes.io |
Here's a simple example using HTML, CSS, and JavaScript to fetch and display product data from the Fake Store API:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fake Store Products</title>
<style>
#products-container {
display: flex;
flex-wrap: wrap;
}
.product {
border: 1px solid #ccc;
padding: 10px;
margin: 10px;
width: 200px;
}
</style>
</head>
<body>
<h1>Fake Store Products</h1>
<div id="products-container"></div>
<script>
// Fetch data from the Fake Store API
fetch('https://fakestoreapi.com/products')
.then(response => response.json())
.then(products => {
const productsContainer = document.getElementById('products-container');
// Create a card for each product
products.forEach(product => {
const productCard = document.createElement('div');
productCard.classList.add('product');
productCard.innerHTML = `
<h3>${product.title}</h3>
<p>${product.description}</p>
<strong>$${product.price}</strong>
`;
productsContainer.appendChild(productCard);
});
})
.catch(error => console.error('Error fetching data:', error));
</script>
</body>
</html>
```
Save this code in an HTML file and open it in a web browser. It will fetch product data from the Fake Store API and display basic information about each product on the webpage. Note that this is a basic example, and you might want to enhance it based on your specific requi
To display the product image, rating, and count of ratings, you can modify the JavaScript code accordingly. Here's an updated version of the HTML file:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fake Store Products</title>
<style>
#products-container {
display: flex;
flex-wrap: wrap;
}
.product {
border: 1px solid #ccc;
padding: 10px;
margin: 10px;
width: 200px;
text-align: center;
}
.product img {
max-width: 100%;
height: auto;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Fake Store Products</h1>
<div id="products-container"></div>
<script>
// Fetch data from the Fake Store API
fetch('https://fakestoreapi.com/products')
.then(response => response.json())
.then(products => {
const productsContainer = document.getElementById('products-container');
// Create a card for each product
products.forEach(product => {
const productCard = document.createElement('div');
productCard.classList.add('product');
productCard.innerHTML = `
<img src="${product.image}" alt="${product.title}" />
<h3>${product.title}</h3>
<p>${product.description}</p>
<p>Rating: ${product.rating.rate} (${product.rating.count} reviews)</p>
<strong>$${product.price}</strong>
`;
productsContainer.appendChild(productCard);
});
})
.catch(error => console.error('Error fetching data:', error));
</script>
</body>
</html>
```
In this version, I added a paragraph (`<p>`) element to display the product rating and count of ratings. Adjust the styling and layout as needed for your preferences. Save the updated code in an HTML file and open it in a web browser to view the product information including the image, rating, and count of ratings.
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team