I'm working on an exercise using array methods, unshift() and shift() among them. In the script below I'm attempting to log an ID from the user, such as "B123" and log their corresponding bid such as "1250." I want to list each bid and id in order from greatest to least bid amount.

This is a learning exercise, not an assignment for marks (it is optional and causing me some trouble) I have included very detailed notes in my script. Could you look at it?

The output right now is: "[Object HTMLInputElement]" in the current high bid field and "Nan{Nan)O" in the Bid history field.

Any advice is always very appreciated. Thanks!

<title>Auction Log</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var bids = new Array();
var bidders = new Array();
var bidTime = new Array();

function writeBid() {
	// write the bidding history and the highest current bid to the webpage
	var historyText= ""; // set the initial value of historyText to an empty text string
	/* Insert a For loop in which the counter variable goes from 0 through the length of the bids array in increments of 1. Each time through the loop, append the following text string the the historyText variable: bidTime bids (bidders) \n, where bidTime, bids and bidders are the current items in each array based on the value of the counter variable.*/
	for (i =0; i < bids.length; i++); {
	historyText= (+bidTime[i] +bids[i] +"("+ +bidders[i] +")"+ +'\n'); 
/* After the For loop finishes, write the value of the historyText variable to the text area box with the name bidList*/
document.bidForm.bidList.value = historyText;
// write the value of the first item in the bids array to the highBid field
document.bidForm.highBid.value = bids[0];
/* set the values of the bidId and bidAmount fields to empty text strings */
document.bidForm.bidId.value = " ";
document.bidForm.bidAmount.value = " ";

function addBid() {
	// A function that will add a bid to the start of the bids, bidders, and bidTime arrays
	/* using the unshift() array method, insert the current value of the bidId field to the start of the bidders array */
	/* use the unshift() array method to insert the current value of the bidAmount field at the start of the bids array */
	// declare a variable named now containing a date object for the current date and time 
	var now = new Date();
	/* extract the hours, minutes and seconds values from the now variable, storing these values in variables named hours, minutes, and seconds. Use a conditional operator to insert a leading zero in the minutes and seconds values if they are less than 10*/
	var hours = now.getHours();
	var minutes = now.getMinutes();
	minutes = (minutes < 10) ? "0"+minutes: minutes;
	var seconds = now.getSeconds();
	seconds = (seconds < 10) ? "0"+seconds: seconds;
	/* create a variable name timeText equal to the text [hours:minutes:seconds] */
	var timeText = (hours +":"+ minutes + ":" + seconds);
	/* using the unshift array method, insert the value of the timeText variable at the start of the bidTime array */
	//call the writeBid() function

function removeBid() {
// removes the first entry from the bids, bidders, and bidTime arrays

/* usign the shift() array method, remove the first entry from the bids array, repeating for the frist entry in the bidders and bidTime arrays */
	//call the writeBid() function

/* Scroll down the document to the Submit input button.  Add an event handler attribute to run the addBid() function when the button is clicked*/


<form name="bidForm" id="bidForm">

<div id="head">
     <a href="#">Home</a> <a href="#">Auctions</a>
     <a href="#">Features</a> <a href="#">Schedule</a>
     <a href="#">Contacts</a>
  <img src="logo.jpg" alt="Schmitt Auction Haus" /></div>

<div id="intro">
   <h1>Silent Auction</h1>
   <h2>Tawney Farm</h2>
   <table id="summarytable" border="2">
         <th>Lot #121</th>
         <td>TurfTuff Lawn Tractor X24 (2003)</td>
         <th>Current High Bid</th>
            <input id="highBid" name="highBid" readonly="readonly" />
         <th>Bidding Ends</th>

   <table id="newbidtable" border="2">
         <th colspan="2" id="newtitle">Enter New Bid</th>
         <th>Bidder ID</th>
            <input id="bidId" name="bidId" />
         <th>Bid Amount</th>
            <input id="bidAmount" name="bidAmount" />
         <th id="buttons" colspan="2">
            <input type="button" value="Submit" onClick="addBid()" />
            <input type="button" value="Remove Last Bid" onClick="removeBid()" />


<div id="bidHistory">
   <h1>Bid History</h1>
      <textarea id="bidList" name="bidList"></textarea>

   Schmitt AuctionHaus &#183;
   3401 Rural Route 4 &#183;
   Fenbrook, IN  38012


Your code assumes there is an existing bid but the code starts with no bids.

also line 16 should be:

historyText=historyText+ bidTime[i].toString()+' '+bids[i].toString() +' ('+ bidders[i].toString() +')\n';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.