Created
October 12, 2016 01:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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