been working on this code. I want it to produce my array so it looks like this:
[0] cat
[1] dog
[2] *Whatever value entered by user*
Currently, it produces this
Pushed: *User Entered Value*
cat,dog,*user entered value*
Here's my code.
var array = ["cat", "dog"];
window.onload = function menu(){
var selection = prompt("Please use this menu, and type 1 to push an item on the array, 2 to pop an item off the array, and 3 to exit the menu.");
if (selection == '1'){
var push = prompt("What item would you like to push onto the array?");
while (push != null) {
array.push(push);
document.getElementById("pushed").innerHTML = "Pushed: " + "<em>" + push + "</em>" + "<br>" + "<br>" + array.toString() + "<hr>";
menu();
}
}
}
while (push != null). This will only enter the loop if the test is true. You don't change the value of push inside the loop, so its value will not change and so it will never exit the loop.