// Define an array of objects to store tool information
const tools = [
{ id: 1, name: "Hammer", category: "Hand Tools", price: 19.99, rating: 4.5 },
{ id: 2, name: "Drill", category: "Power Tools", price: 49.99, rating: 4.8 },
{ id: 3, name: "Shovel", category: "Gardening Tools", price: 29.99, rating: 4.3 },
// Add more tool objects as needed
];
// Function to display tools in a grid layout
function displayTools() {
const toolContainer = document.getElementById("tool-container");
toolContainer.innerHTML = ''; // Clear previous content
tools.forEach(tool => {
const toolCard = document.createElement("div");
toolCard.classList.add("tool-card");
const toolName = document.createElement("h3");
toolName.textContent = tool.name;
const toolCategory = document.createElement("p");
toolCategory.textContent = `Category: ${tool.category}`;
const toolPrice = document.createElement("p");
toolPrice.textContent = `Price: $${tool.price}`;
const toolRating = document.createElement("p");
toolRating.textContent = `Rating: ${tool.rating}`;
toolCard.appendChild(toolName);
toolCard.appendChild(toolCategory);
toolCard.appendChild(toolPrice);
toolCard.appendChild(toolRating);
toolContainer.appendChild(toolCard);
});
}
// Call the displayTools function to initially display tools
displayTools();
Comments
Post a Comment