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 timeObject = document.querySelector("#timeLeft");
let timeLeft = 60;
//Defined the seconds left ^^
//Created a function that executes every second subtracting timeleft by 1, setting the timeObject to that value, and when the timer = 0 it will say the highest bid.
const countInterval = setInterval(() => {
timeLeft--;
timeObject.textContent = `${timeLeft} seconds left...`;
if (timeLeft === 0) {
clearInterval(countInterval);
bidInput.disabled = true;
alert(`The bidding has ended. The winning bid is $${currentHighestBid}!`);
}
}, 1000);