d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Not Sure What To Do
Add Reply New Topic New Poll
Member
Posts: 10,803
Joined: Apr 5 2010
Gold: 20.00
Dec 14 2015 11:28am
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
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Dec 14 2015 07:05pm
where is your logic?

Quote
the job is to fine the middle value


i dont see anything there that looks for the middle value.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll