[Javascript] array question

Steve Snow sjsnow at ozconnect.net
Tue Mar 25 18:32:47 CST 2003


My situation is similar to the person who wants to display 1000 array items.

I have some weather data held in arrays (max temp, min temp, rainfall
average for the month, average pressure) etc - all in single arrays
containing the 12 items.

I want to be able to display them in table format with the following:

Column 1, row 1 - Average Max Temp
Column 2, row 1 - Average Min Temp
Etc

In row 2, I want to display the array data relevant to the value.

The material (row 2 data) is updated each new month. The following is the
javascript I have so far for the above that works without tables. How can I
get it to work within a table so the formatting is better? Thanks.

The Javascript concerned:

    <p>     <SCRIPT LANGUAGE="Javascript"><!--
// Get today's current date.
var now = new Date();

// Array list of days.
var days = new
Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'
);

// Array list of months.
var months = new
Array('January','February','March','April','May','June','July','August','Sep
tember','October','November','December');

// Array list of max temps.
var maxtemps = new
Array('32.1','31.4','31.3','31.0','29.9','28.3','27.6','28.4','30.1','31.5',
'33.1','33.1');

// Array list of min temps.
var mintemps = new
Array('24.5','24.4','23.9','23.1','22.7','21.1','20.2','19.2','19.6','21.1',
'23.3','24.4');

// Array list of 9am RH.
var rh09 = new
Array('76%','80%','78%','73%','71%','70%','72%','69%','66%','65%','66%','70%
');

// Array List of 3pm RH.
var rh15 = new
Array('68%','72%','69%','65%','65%','63%','64%','59%','57%','57%','56%','62%
');

// Array list of monthly rainfall data
var monthlyrain = new
Array('280.1','295.9','263.8','184.7','71.1','34.0','22.5','5.1','3.4','7.9'
,'40.8','170.7');

// Array list of Sunshine.
var sunshine = new
Array('6.1','5.1','6.0','7.5','7.7','7.5','7.7','9.1','9.8','10.2','9.7','7.
8');

// Array list of MSLP.
var mslp = new
Array('1006.7','1006.7','1008.6','1010.1','1011.5','1012.8','1013.5','1013.8
','1012.9','1011.3','1009.2','1008.0');

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

// Calculate four digit year.
function fourdigits(number)	{
	return (number < 1000) ? number + 1900 : number;
								}
// Join it all together
today =  days[now.getDay()] + ", " +
              months[now.getMonth()] + " " +
               date + ", " +
                (fourdigits(now.getYear())) ;

// Print out the data.

document.writeln("<BR><BIG><BIG>Today\'s date is " +today+ ".");
document.writeln("<BR><U>Average Climatic Details in Gove for the month of "
+months[now.getMonth()]);
document.writeln("<br><BR></U>Max Temp " +maxtemps[now.getMonth()]);
document.writeln("<BR>Min Temp " +mintemps[now.getMonth()]);
document.writeln("<BR>Relative Humidity 9am " +rh09[now.getMonth()]);
document.writeln("<BR>Relative Humidity 3pm " +rh15[now.getMonth()]);
document.writeln("<BR>Monthly Rainfall " +monthlyrain[now.getMonth()]);
document.writeln("<BR>Sunshine (HRS) " +sunshine[now.getMonth()]);
document.writeln("<BR>Mean Sea-Level Pressure " +mslp[now.getMonth()]);

//--></SCRIPT>






More information about the Javascript mailing list