I need to write out maximum distance and the days on which it was run, but I don't know how to do it using arrays for two different weeks and display one day with the distance from var weekBeginning = '12 July 2010' and two days with the distance from var weekBeginning = '19 July 2010'.
Any help appreciated.
<HTML>
<HEAD>
<TITLE>
Jogging Summary
</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="tma03.css">
<SCRIPT LANGUAGE = "JavaScript">
/*
* M150 TMA03 2010J Q3.
* Program to analyse the distances run by a jogger each day over the course of a week.
*/
//days of the week
var dayArray =
['Mon', 'Tue', 'Wed', 'Thu', 'Fri','Sat', 'Sun'];
//date of a sample week
var weekBeginning = '12 July 2010'
//distance in kilometres run each day in the sample week
var distanceArray = [2,4,2,1,5,4,3];
//second sample week
//Part (v) uncomment the next two lines.
weekBeginning = '19 July 2010'
distanceArray = [2,6,3,1,6,4,2];
//Part (i)
//Add code to display a heading, then a blank line,
document.write('Summary for the week begining 12 July 2010' + '<BR>' + '<BR>');
// then the information for each of the seven days.
for (var day = 1; day < dayArray.length; day = day + 1)
{
document.write(dayArray[day] + ' : ' + distanceArray[day] + ' km' + '<BR>' + '<BR>');
}
//Variable to hold the maximum value in distance array.
var maximumDistance;
maximumDistance = 0;
//Part (ii)
//Add code to find the maximum distance.
for (var distance = 1; distance < distanceArray.length; distance = distance + 1)
{
if (distanceArray[distance] > distanceArray[maximumDistance])
{
maximumDistance = distance;
}
}
//Part (iv)
//Add code that will write out the maximum distance and the days it was run on in a suitable message.
document.write('The maximum distance was ' + distanceArray[maximumDistance]
+' km on ' + dayArray[maximumDistance] + '.' + '<BR>');
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>


Sign In
Create Account


Back to top









