Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i have posted what i have so far but i need to make it so it displays the states

ID: 3641478 • Letter: I

Question

i have posted what i have so far but i need to make it so it displays the states you enter in alphabetical order...can you help me?



<html>
<body>
<script type="text/javascript">

// Program name: stateArray.html
// Purpose: Creates an array for five state names,
// prompts the user to enter them, and then displays them
// Author: Brandon Williams
// Date last modified: 04-April-2012

// Declare variables and constants
var SIZE = 5; // array size
var index; // loop variable
var ES = ""; // empty string
var BR = "<br />"; // HTML line break

// State program purpose
document.write("This program asks you to enter the names of five states." + BR);

// Declare array
var states = new Array(SIZE);

// Loop to prompt for names of cities
for(index = 0; index < SIZE; index++) {
states[index] = prompt("Enter the name of a state:",ES);
}

// Display contents of array
document.write("Here are the states you entered:" + BR);
for (index = 0; index < SIZE; index++) {
document.write(states[index] + BR);
}

</script>

Explanation / Answer

Insert: ... states.sort(); ... at some point before you display the contents to alphabetically sort the list automatically.