<!-- JavaScript:Arrays code snippet 6. -->
<!-- A 'for loop' with parallel arrays. -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Code source: http://www.justfigures.co.uk/ -->
<!-- A resource for web developers using XHTML, CSS, JavaScript, PHP -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View code snippet page</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
//<![CDATA[
/* collect a known number of data items linked to descriptors,
store them in parallel arrays and write data items with associated descriptors */
// create an array and fill with data
var weekDayArray = ['Mon','Tues','Wed','Thurs','Fri'];
// create an empty array the same length as the first
var temperatureArray = new Array (5);
// iterate through parallel array in input prompt window
for (var question = 0; question < temperatureArray.length; question = question + 1)
{
temperatureArray[question] = window.prompt('Enter temperature for '+ weekDayArray[question],'');
}
// write parallel array in output to browser
document.write('Confirmation of the temperatures:' + '<br />');
for (var question = 0; question < temperatureArray.length; question = question + 1)
{
document.write(weekDayArray[question]+' '+temperatureArray[question] + '<br />');
}
//]]>
</script>
</body>
</html>