Javascript push not working

I am doing a straightforward task wright here users can push or pop items onto the variety. My difficulty is, as soon as they press an object on and attempt to push an additional on, it doesn"t add it onto the list, it simply reareas the last value that they included to the selection.

home window.onpack = feature menu(){var variety = <"cat", "dog">;var selection = prompt("Please usage this food selection, and form 1 to press an item on the array, 2 to pop a things off the range, and also 3 to leave the food selection.");if (selection == "1") var press = prompt("What item would you favor to press onto the array?"); while (press != null) selection.push(push); record.getElementById("pushed").innerHTML = range.toString(); menu();Then down below I have actually an HTML page, yet right here is where it displays:


*

The menu() function redefines the range eincredibly time it is dubbed, fairly than modifying an range external its scope.

You watching: Javascript push not working

Move the var variety = <"cat", "dog">; line to the height to fix this prompt trouble.

See more: Music Randomly Starts Playing Android, Fix Random Audio Files Playing On Android

var array = <"cat", "dog">;attribute menu() var selection = prompt("Please usage this menu, and type 1 to press an object on the array, 2 to pop a things off the range, and also 3 to exit the menu."); if (selection == "1") var press = prompt("What item would certainly you prefer to press onto the array?"); while (press != null) selection.push(push); record.getElementById("pushed").innerHTML = variety.toString(); menu(); home window.onload = menu;

References

JS Scope

onload usage


*

Thanks for contributing an answer to Stack Overflow!

Please be sure to answer the question. Provide details and also share your research!

But avoid

Asking for aid, clarification, or responding to various other answers.Making statements based on opinion; earlier them up via referrals or individual experience.

See more: Windows 10 Quick Access Rename, Rename Quick Access Pinned Folders In Windows 10

To learn even more, see our tips on composing great answers.


Message Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of company, privacy plan and cookie plan


Not the answer you're looking for? Browse other questions tagged javascript html or ask your own question.


Which “href” worth must I use for JavaScript links, “#” or “javascript:void(0)”?
*

site architecture / logo design © 2021 Stack Exreadjust Inc; user contributions licensed under cc by-sa. rev2021.4.1.38970


Stack Overflow functions finest with JavaScript allowed
*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange deserve to save cookies on your tool and also disclose information in accordance with our Cookie Policy.