when executed it prompts the user word until the word quit is entered then breaks. the job is to fine the middle value there are no evens.
The User Entered Strings
no
yes
maybe
The number of strings entered for this run was: 3
The content of the slot halfway through the array: undefined
function project5Part4() {
// Define all variables
var userEnteredString; // will contain the string entered by the user
var arrayIndex;
var stringArray = []; // will contain any number of user entered strings
var outputList; // will contain a ref to the ordered list on the web page
var firstSubHeading; // will contain a ref to the first sub heading
var secondSubHeading; // will contain a ref to the second sub heading
var listHolder
var outputHolder;
var middleHolder;
// Loop to obtain and place any number of strings from user into the string array
while (userEnteredString !== "quit") {
userEnteredString = prompt("Enter a string\nIf finished, enter 'quit'"); // obtain a string
if (userEnteredString === "quit") {
alert("Program is halting as requested");
break;
}
arrayIndex = stringArray.length; // point index at next open slot of array
stringArray[arrayIndex] = userEnteredString; // place string into next open slot of array
}
// Generate a reference to the ordered list on the web page so we can add line items
// to it.
// (Note that for this program, the html ordered list element itself is already present
// in the html, and does not have to be inserted by this JavaScript program.)
outputList = document.getElementById("listToDisplayEnteredStrings");
// Loop through the string array placing the content of each element (aka "slot") in turn
// onto the web page in the form of items in an ordered list
arrayIndex = 0; // point index at first row of the array
while (arrayIndex < stringArray.length) {
outputList.innerHTML += "<li>" + stringArray[arrayIndex] + "</li>";
arrayIndex++;
}
// Next, check to make sure the user entered an odd (as opposed to even) number of strings
// before showing any more output that just the strings he/she entered.
if (stringArray.length % 2 !== 1) {
alert("You must enter an ODD number of strings."
+ "\n\nIgnore program output from this run."
+ "\nExecution terminating--please start over."
+ "\n");
return; // return from the mainline to the web page and thus stop
}
// Place the number of strings entered by the user into the first sub heading on the Web page
firstSubHeading = document.getElementById("headingForNumber"); // generate ref to 1st subheading
firstSubHeading.innerHTML += stringArray.length;
// Place the string from the middle element (aka "slot") of the array into the second sub heading on the web page
outputHolder = document.getElementById("headingForMiddleSlotContent");
outputHolder.innerHTML += middleHolder;
not sure what to add to this
} // END OF FUNCTION
This post was edited by jsbb on Dec 14 2015 11:28am