test
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body{
|
||||
margin:0;
|
||||
background: lightgray;
|
||||
}
|
||||
.slidebar{
|
||||
background: blue;
|
||||
color: white;
|
||||
}
|
||||
.dashboard{
|
||||
display:flex;
|
||||
main-height:100vh;
|
||||
}
|
||||
.slidebar a{
|
||||
display:block;
|
||||
color: white
|
||||
text-decaration:none;
|
||||
padding: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div class="dashboard">
|
||||
<aside class="slidebar">
|
||||
<h2>mydashboard</h2>
|
||||
<a href="#">dasboard</a>
|
||||
<a href="#">statistik</a>
|
||||
<a href="#">data siswa</a>
|
||||
<a href="#">pemgaturan</a>
|
||||
</aside>
|
||||
<main class="main">
|
||||
<h1>dashboard siswa</h1>
|
||||
<p>tahun ajaran 2026/2027</p>
|
||||
<section class="card">
|
||||
<div></div>
|
||||
</section>
|
||||
|
||||
</main><div>
|
||||
\</div><body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,113 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Project 07 - Shopping Cart</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
</head>
|
||||
<body class="bg-gray-100 p-4">
|
||||
<div class="max-w-6xl mx-auto">
|
||||
|
||||
<h1 class="text-3xl font-bold text-center mb-6">
|
||||
Product Catalog
|
||||
</h1>
|
||||
|
||||
<input
|
||||
type="search"
|
||||
id="searchBox"
|
||||
oninput="filterProducts()"
|
||||
placeholder="Search product..."
|
||||
class="w-full p-3 mb-6 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
|
||||
<div id="product-list" class="grid grid-cols-1 lg:grid-cols-3 gap-4"></div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="max-w-6xl mx-auto flex flex-col lg:flex-row gap-6">
|
||||
|
||||
<!-- Product Catalog Grid -->
|
||||
<div class="w-full lg:w-2/3 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
|
||||
|
||||
<!-- Product 1 -->
|
||||
<div class="bg-white p-4 rounded shadow">
|
||||
<img src="images/controller.jpeg" alt="Controller" class="w-full h-40 object-cover mb-4">
|
||||
<h3 class="font-bold text-lg">Controller</h3>
|
||||
<p class="text-gray-600">Rp 750.000</p>
|
||||
<button data-name="Controller" data-price="750000" class="add-to-cart-btn mt-2 bg-blue-500 text-white px-4 py-2 rounded w-full hover:bg-blue-600">Add to Cart</button>
|
||||
</div>
|
||||
|
||||
<!-- Product 2 -->
|
||||
<div class="bg-white p-4 rounded shadow">
|
||||
<img src="images/headset.png" alt="Headset" class="w-full h-40 object-cover mb-4">
|
||||
<h3 class="font-bold text-lg">Headset</h3>
|
||||
<p class="text-gray-600">Rp 1.200.000</p>
|
||||
<button data-name="Headset" data-price="1200000" class="add-to-cart-btn mt-2 bg-blue-500 text-white px-4 py-2 rounded w-full hover:bg-blue-600">Add to Cart</button>
|
||||
</div>
|
||||
|
||||
<!-- Product 3 -->
|
||||
<div class="bg-white p-4 rounded shadow">
|
||||
<img src="images/keyboard.jpg" alt="Keyboard" class="w-full h-40 object-cover mb-4">
|
||||
<h3 class="font-bold text-lg">Keyboard</h3>
|
||||
<p class="text-gray-600">Rp 1.800.000</p>
|
||||
<button data-name="Keyboard" data-price="1800000" class="add-to-cart-btn mt-2 bg-blue-500 text-white px-4 py-2 rounded w-full hover:bg-blue-600">Add to Cart</button>
|
||||
</div>
|
||||
|
||||
<!-- Product 4 -->
|
||||
<div class="bg-white p-4 rounded shadow">
|
||||
<img src="images/laptop.jpg" alt="Laptop" class="w-full h-40 object-cover mb-4">
|
||||
<h3 class="font-bold text-lg">Laptop</h3>
|
||||
<p class="text-gray-600">Rp 14.985.000</p>
|
||||
<button data-name="Laptop" data-price="14985000" class="add-to-cart-btn mt-2 bg-blue-500 text-white px-4 py-2 rounded w-full hover:bg-blue-600">Add to Cart</button>
|
||||
</div>
|
||||
|
||||
<!-- Product 5 -->
|
||||
<div class="bg-white p-4 rounded shadow">
|
||||
<img src="images/monitor.jpeg" alt="Monitor" class="w-full h-40 object-cover mb-4">
|
||||
<h3 class="font-bold text-lg">Monitor</h3>
|
||||
<p class="text-gray-600">Rp 3.000.000</p>
|
||||
<button data-name="Monitor" data-price="3000000" class="add-to-cart-btn mt-2 bg-blue-500 text-white px-4 py-2 rounded w-full hover:bg-blue-600">Add to Cart</button>
|
||||
</div>
|
||||
|
||||
<!-- Product 6 -->
|
||||
<div class="bg-white p-4 rounded shadow">
|
||||
<img src="images/mouse_logitech.jpg" alt="Mouse Logitech" class="w-full h-40 object-cover mb-4">
|
||||
<h3 class="font-bold text-lg">Mouse Logitech</h3>
|
||||
<p class="text-gray-600">Rp 600.000</p>
|
||||
<button data-name="Mouse Logitech" data-price="600000" class="add-to-cart-btn mt-2 bg-blue-500 text-white px-4 py-2 rounded w-full hover:bg-blue-600">Add to Cart</button>
|
||||
</div>
|
||||
<!-- product 7 -->
|
||||
<div class="bg-white p-4 rounded shadow">
|
||||
<img src="images/speaker.jpeg" alt="speaker" class="w-full h-40 object-cover mb-4">
|
||||
<h3 class="font-bold text-lg">speaker</h3>
|
||||
<p class="text-gray-600">Rp 800.000</p>
|
||||
<button data-name="speaker" data-price="800000" class="add-to-cart-btn mt-2 bg-blue-500 text-white px-4 py-2 rounded w-full hover:bg-blue-600">Add to Cart</button>
|
||||
</div>
|
||||
|
||||
<div class="bg-white p-4 rounded shadow">
|
||||
<img src="images/webcam.jpeg" alt="webcam" class="w-full h-40 object-cover mb-4">
|
||||
<h3 class="font-bold text-lg">webcam</h3>
|
||||
<p class="text-gray-600">Rp 1.200.000</p>
|
||||
<button data-name="webcam" data-price="1200000" class="add-to-cart-btn mt-2 bg-blue-500 text-white px-4 py-2 rounded w-full hover:bg-blue-600">Add to Cart</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="w-full lg:w-1/3 bg-white p-6 rounded shadow h-fit">
|
||||
<h2 class="text-2xl font-bold mb-4">Keranjang Belanja</h2>
|
||||
|
||||
<p id="empty-cart-msg" class="text-gray-500 italic mb-4">Keranjang masih kosong</p>
|
||||
<ul id="cart-items" class="mb-4 space-y-2"></ul>
|
||||
|
||||
<div class="border-t pt-4 font-bold text-xl">
|
||||
Total: Rp <span id="cart-total">0</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="javascriptngelu.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,62 @@
|
||||
let cart = [];
|
||||
|
||||
const cartItemsContainer = document.getElementById('cart-items');
|
||||
const cartTotalElement = document.getElementById('cart-total');
|
||||
const emptyCartMsg = document.getElementById('empty-cart-msg');
|
||||
const addButtons = document.querySelectorAll('.add-to-cart-btn');
|
||||
|
||||
|
||||
addButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const name = this.getAttribute('data-name');
|
||||
const price = parseFloat(this.getAttribute('data-price'));
|
||||
|
||||
cart.push({ name, price });
|
||||
renderCart();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
cartItemsContainer.addEventListener('click', function () {
|
||||
if (event.target.matches('.remove-btn') || event.target.closest('.remove-btn')) {
|
||||
const itemIndex = event.target.getAttribute('data-index');
|
||||
cart.splice(itemIndex, 1);
|
||||
renderCart();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function renderCart() {
|
||||
cartItemsContainer.innerHTML = '';
|
||||
|
||||
let total = 0;
|
||||
|
||||
if (cart.length === 0) {
|
||||
emptyCartMsg.style.display = 'block';
|
||||
} else {
|
||||
emptyCartMsg.style.display = 'none';
|
||||
|
||||
cart.forEach((item, index) => {
|
||||
total += item.price;
|
||||
|
||||
const li = document.createElement('li');
|
||||
li.className = 'flex justify-between items-center bg-gray-50 p-2 rounded border';
|
||||
|
||||
const span = document.createElement('span');
|
||||
// Mengubah format harga menjadi style Rupiah (id-ID)
|
||||
span.textContent = `${item.name} - Rp ${item.price.toLocaleString('id-ID')}`;
|
||||
|
||||
const removeBtn = document.createElement('button');
|
||||
removeBtn.textContent = 'Remove';
|
||||
removeBtn.className = 'remove-btn bg-red-500 text-white px-2 py-1 rounded text-sm hover:bg-red-600';
|
||||
removeBtn.setAttribute('data-index', index);
|
||||
|
||||
li.appendChild(span);
|
||||
li.appendChild(removeBtn);
|
||||
cartItemsContainer.appendChild(li);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
cartTotalElement.textContent = total.toLocaleString('id-ID');
|
||||
}
|
||||
Reference in New Issue
Block a user