OneCompiler

VGBRE

89


Example heading with h2 size

Example heading with h3 size

Following is sample java code.

int i = 10;
if(i>0){
    System.out.println('positive');
}
```let cart = [];
let currentPage = 1;

function addToCart(product, price) {
  cart.push({ product, price });
  document.getElementById('cart-count').textContent = cart.length;
  alert(`${product} has been added to your cart!`);
}

function viewCart() {
  if (cart.length === 0) {
    alert('Your cart is empty!');
  } else {
    let cartDetails = 'Your Cart:\n';
    cart.forEach((item, index) => {
      cartDetails += `${index + 1}. ${item.product} - $${item.price}\n`;
    });
    alert(cartDetails);
  }
}

function searchProduct() {
  const searchQuery = document.querySelector('.search-bar input').value.toLowerCase();
  alert(`Searching for: ${searchQuery}`);
}

function filterByCategory() {
  const category = document.getElementById('category').value;
  alert(`Filtering products by category: ${category}`);
}

function filterByPrice() {
  const price = document.getElementById('price-range').value;
  document.getElementById('price-value').textContent = `Max: $${price}`;
  alert(`Filtering products by price range: $0 - $${price}`);
}

function filterByRating() {
  const rating = document.getElementById('rating').value;
  alert(`Filtering products by rating: ${rating} stars`);
}

function changePage(direction) {
  if (direction === 'prev' && currentPage > 1) {
    currentPage--;
  } else if (direction === 'next') {
    currentPage++;
  }
  alert(`Page changed to: ${currentPage}`);
}