Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thaiall
Created October 12, 2016 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thaiall/ac43d83bd9ce69f34d1a7b3f682e4582 to your computer and use it in GitHub Desktop.
Save thaiall/ac43d83bd9ce69f34d1a7b3f682e4582 to your computer and use it in GitHub Desktop.
get number value to store in array and do loop to process and choose from array.
<script>
var ar = new Array();
ar[0] = window.prompt("put a number"); // 3
ar[1] = window.prompt("put a number"); // 4
ar[2] = window.prompt("put a number"); // 5
ar[3] = window.prompt("put a number"); // 6
ar[4] = window.prompt("put a number"); // 7
window.alert(ar.length); // 5
var keep = "";
for (idx in ar) { keep += ar[idx]; }
window.alert(keep); // 34567
keep = "";
for (i = 0; i < ar.length; i++) {
if(ar[i] % 2 == 0) { keep += ar[i]; } // >0
}
console.log(keep); // 46 , firefox:ctrl-shift-c , chrome:ctrl-shift-i
// http://www.w3schools.com/js/tryit.asp?filename=tryjs_loop_for
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment