Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
const auctionItem = {
name: "Item Name",
description: "Item Description",
startingBid: 100,
highestBid: 100,
};
let currentHighestBid = 100;
const bidForm = document.querySelector("form");
const bidInput = document.querySelector("#bid-amount");
const currentBidDisplay = document.querySelector("#current-bid");
const highestBidDisplay = document.querySelector("#highest-bid");
bidForm.addEventListener("submit", (event) => {
event.preventDefault();
const newBidAmount = parseInt(bidInput.value);
if (isNaN(newBidAmount) || newBidAmount <= currentHighestBid) {
alert("Invalid bid amount. Please enter a higher bid.");
} else {
currentHighestBid = newBidAmount;
currentBidDisplay.textContent = `$${currentHighestBid}`;
highestBidDisplay.textContent = `$${currentHighestBid}`;
}
});
setInterval(() => {
highestBidDisplay.textContent = `$${currentHighestBid}`;
}, 1000);
const timeDisplay = document.querySelector("#time-remaining");
let timeRemaining = 60;
const countdownInterval = setInterval(() => {
timeRemaining--;
timeDisplay.textContent = `${timeRemaining} seconds`;
if (timeRemaining <= 0) {
clearInterval(countdownInterval);
bidInput.disabled = true;
const winnerMessage = `Auction ended. The winner is John with a bid of $${currentHighestBid}.`;
alert(winnerMessage);
}
}, 1000);
setInterval(() => {
const maxBidAmount = parseInt(document.querySelector("#bid-amount-max").value);
if (maxBidAmount > currentHighestBid) {
currentHighestBid += 1;
currentBidDisplay.textContent = `$${currentHighestBid}`;
highestBidDisplay.textContent = `$${currentHighestBid}`;
}
}, 1000);