Experiment 11
Experiment 11
Experiment 11
return (
<div>
<h2>Product List</h2>
{products.map((product, index) => (
<li key={index}>
<span>{product.name} - ${product.price}</span>
<button onClick={() => addToCart(product)}>Add to Cart</button>
</li>
))}
</ul>
<h2>Cart</h2>
<ul>
{cart.map((item, index) => (
<li key={index}>
{item.name} - ${item.price}
</li>
))}
</ul>
</div>
);
};
return (
<div>
<h2>Todo List</h2>
<ul>
{todos.map((todo, index) => (
<li key={index}>
<input
type="checkbox"
checked={todo.completed}
onChange={() => toggleTodo(index)}
/>
<span style={{ textDecoration: todo.completed ? 'line-through' : 'none' }}>
{todo.title}
</span>
</li>
))}
</ul>
</div>
);
};