-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
162 lines (140 loc) · 4.82 KB
/
script.js
File metadata and controls
162 lines (140 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const products = [
{
id: 1,
name: "Intel Core i9-12900K",
price: 589,
img: "https://static.webx.pk/files/19643/Images/18-czone.com.pk-1540-12707-060122094350-19643-0-020322085129089.jpg"
},
{
id: 2,
name: "NVIDIA GeForce RTX 3080",
price: 699,
img: "https://techmatched.pk/wp-content/uploads/2023/11/4-10.png"
},
{
id: 3,
name: "Corsair Vengeance 16GB RAM",
price: 89,
img: "https://images.unsplash.com/photo-1549924231-f129b911e442?auto=format&fit=crop&w=500&q=80"
},
{
id: 4,
name: "Samsung 970 EVO SSD 1TB",
price: 150,
img: "https://images.unsplash.com/photo-1517336714731-489689fd1ca8?auto=format&fit=crop&w=500&q=80"
},
{
id: 5,
name: "ASUS ROG Strix Z690 Motherboard",
price: 399,
img: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS07_dq7UXdm6n-k-LrheKfAtMpY_IIJFmwSQ&s"
},
{
id: 6,
name: "Cooler Master Hyper 212 CPU Cooler",
price: 45,
img: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ6r9rU0PJmboOkXTNyfp4Add4FTTeAbtMTWg&s"
},
{
id: 7,
name: "Seagate BarraCuda 2TB HDD",
price: 60,
img: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTGU4jqO06rTccwEM9PmtRD05p45XncbkRV9A&s"
},
{
id: 8,
name: "EVGA 750W Power Supply",
price: 120,
img: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTPKMTGvvbSlnnLSgDmy2vhTk4FsSucZvv7aw&s"
}
];
const productList = document.getElementById('product-list');
products.forEach(prod => {
const card = document.createElement('div');
card.className = 'card';
card.innerHTML = `
<img src="${prod.img}" alt="${prod.name}" />
<div class="card-body">
<h5 class="card-title">${prod.name}</h5>
<p class="card-text">$${prod.price}</p>
<button class="add-cart-btn" onclick="addToCart(${prod.id})">Add to Cart</button>
</div>
`;
productList.appendChild(card);
});
// Simple Add to Cart Function
function addToCart(id) {
const product = products.find(p => p.id === id);
alert(`Added "${product.name}" to cart!`);
}
// Simple Cart Add function (just alert)
function addToCart(id) {
const product = products.find(p => p.id === id);
alert(`Added "${product.name}" to cart!`);
}
// Testimonial Carousel Logic
const testimonials = document.querySelectorAll('.testimonial-card');
let currentTestimonial = 0;
function showTestimonial(index) {
testimonials.forEach((t, i) => {
t.classList.remove('active');
if(i === index) t.classList.add('active');
});
}
function nextTestimonial() {
currentTestimonial = (currentTestimonial + 1) % testimonials.length;
showTestimonial(currentTestimonial);
}
// Initialize
showTestimonial(currentTestimonial);
setInterval(nextTestimonial, 3000); // change testimonial every 3 seconds
let cartCount = 0;
let cartItems = [];
// Select all "Add to Cart" buttons
document.querySelectorAll(".offer-card .btn").forEach(button => {
button.addEventListener("click", function () {
const productCard = this.closest(".offer-card");
const productName = productCard.querySelector("h3").innerText;
const productPrice = productCard.querySelector("strong").innerText;
// Add to cart array
cartItems.push({ name: productName, price: productPrice });
cartCount++;
document.getElementById("cart-count").innerText = cartCount;
alert(`${productName} added to cart!`);
});
});
// Example: Show cart items when cart button is clicked
document.getElementById("cartBtn").addEventListener("click", function () {
if (cartItems.length === 0) {
alert("Your cart is empty!");
} else {
let cartDetails = "🛒 Your Cart:\n\n";
cartItems.forEach((item, index) => {
cartDetails += `${index + 1}. ${item.name} — ${item.price}\n`;
});
alert(cartDetails);
}
});
document.getElementById('contactForm').addEventListener('submit', function(e) {
e.preventDefault();
alert("Thank you for contacting us! We will get back to you soon.");
this.reset();
});
// Countdown Timer (Set date to 14th August midnight)
const countdownDate = new Date("Aug 14, 2025 00:00:00").getTime();
function updateCountdown() {
const now = new Date().getTime();
const distance = countdownDate - now;
const days = Math.floor(distance / (1000 * 60 * 60 * 24));
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("days").innerText = days;
document.getElementById("hours").innerText = hours;
document.getElementById("minutes").innerText = minutes;
document.getElementById("seconds").innerText = seconds;
if (distance < 0) {
document.querySelector(".countdown").innerHTML = "<h3>🎉 Offer Expired! 🎉</h3>";
}
}
setInterval(updateCountdown, 1000);