galaxiesanddust
12-08-2012, 04:57 AM
The code that I have to work on is supposed to create an array so that when the user enters the number when prompted, it matches and displays the correct president. Right now, the prompt just continues and it ends with the whole list being displayed.
If anyone could give me some assistance with this, it would be greatly appreciated.
<html>
<body>
<script type="text/javascript">
// Program name: presidents.html
// Purpose: Creates an array for users to enter
// a number that matches with the correct President
// Author: Paul Addison
// Date last modified: 01-Sep-2011
// Declare variables and constants
var SIZE = 44; // array size
var presidents; // array for book titles
var index; // loop index
var ES = ""; // empty string
var BR = "<br />"; // HTML line break
// Create presidents array
presidents = new Array(SIZE);
// Prompt user to enter a number
for (index = 0; index < SIZE; index++) {
presidents[index] = prompt("Enter a number" + ":",ES);
presidents[1]="Washington";
presidents[2]="Adams";
presidents[3]="Jefferson";
presidents[4]="Madison";
presidents[5]="Monroe";
presidents[6]="Adams";
presidents[7]="Jackson";
presidents[8]="Van Buren";
presidents[9]="Harrison";
presidents[10]="Tyler";
presidents[11]="Polk";
presidents[12]="Taylor";
presidents[13]="Filmore";
presidents[14]="Pierce";
presidents[15]="Buchanan";
presidents[16]="Lincoln";
presidents[17]="Johnson";
presidents[18]="Grant";
presidents[19]="Hayes";
presidents[20]="Garfield";
presidents[21]="Arthur";
presidents[22]="Cleveland";
presidents[23]="Harrison";
presidents[24]="Cleveland";
presidents[25]="McKinley";
presidents[26]="Roosevelt";
presidents[27]="Taft";
presidents[28]="Wilson";
presidents[29]="Harding";
presidents[30]="Coolidge";
presidents[31]="Hoover";
presidents[32]="Roosevelt";
presidents[33]="Truman";
presidents[34]="Eisenhower";
presidents[35]="Kennedy";
presidents[36]="Johnson";
presidents[37]="Nixon";
presidents[38]="Ford";
presidents[39]="Carter";
presidents[40]="Reagan";
presidents[41]="Bush";
presidents[42]="Clinton";
presidents[43]="Bush";
presidents[44]="Obama";
}
// Display president
document.write("President:" + BR + BR);
for (index = 0; index < SIZE; index++) {
document.write(presidents[index] + BR);
}
// Thank the user and end the program
document.write("Thank you." + BR);
</script>
</body>
</html>
If anyone could give me some assistance with this, it would be greatly appreciated.
<html>
<body>
<script type="text/javascript">
// Program name: presidents.html
// Purpose: Creates an array for users to enter
// a number that matches with the correct President
// Author: Paul Addison
// Date last modified: 01-Sep-2011
// Declare variables and constants
var SIZE = 44; // array size
var presidents; // array for book titles
var index; // loop index
var ES = ""; // empty string
var BR = "<br />"; // HTML line break
// Create presidents array
presidents = new Array(SIZE);
// Prompt user to enter a number
for (index = 0; index < SIZE; index++) {
presidents[index] = prompt("Enter a number" + ":",ES);
presidents[1]="Washington";
presidents[2]="Adams";
presidents[3]="Jefferson";
presidents[4]="Madison";
presidents[5]="Monroe";
presidents[6]="Adams";
presidents[7]="Jackson";
presidents[8]="Van Buren";
presidents[9]="Harrison";
presidents[10]="Tyler";
presidents[11]="Polk";
presidents[12]="Taylor";
presidents[13]="Filmore";
presidents[14]="Pierce";
presidents[15]="Buchanan";
presidents[16]="Lincoln";
presidents[17]="Johnson";
presidents[18]="Grant";
presidents[19]="Hayes";
presidents[20]="Garfield";
presidents[21]="Arthur";
presidents[22]="Cleveland";
presidents[23]="Harrison";
presidents[24]="Cleveland";
presidents[25]="McKinley";
presidents[26]="Roosevelt";
presidents[27]="Taft";
presidents[28]="Wilson";
presidents[29]="Harding";
presidents[30]="Coolidge";
presidents[31]="Hoover";
presidents[32]="Roosevelt";
presidents[33]="Truman";
presidents[34]="Eisenhower";
presidents[35]="Kennedy";
presidents[36]="Johnson";
presidents[37]="Nixon";
presidents[38]="Ford";
presidents[39]="Carter";
presidents[40]="Reagan";
presidents[41]="Bush";
presidents[42]="Clinton";
presidents[43]="Bush";
presidents[44]="Obama";
}
// Display president
document.write("President:" + BR + BR);
for (index = 0; index < SIZE; index++) {
document.write(presidents[index] + BR);
}
// Thank the user and end the program
document.write("Thank you." + BR);
</script>
</body>
</html>