Thursday, October 29, 2015

Odd and Even Number Generator in JavaScript

This sample program that I wrote in JavaScript will show you how to create and use one dimensional array as your data structure to accept input values. I called this program Odd and Even Number Generator what does the program will do is to ask the user to give a series of numbers and then our program will enumerate and classify the odd and even number provided by our user.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.


Program Listing

<html>
 <head>
 <title> Even and Odd Number Generator </title>
 </head>
 <body>
 <h1> Even and Odd Number Generator </h1>
 <script>
    var grades = [];
    var i=0;
          for (i = 0; i < 10; i++) {
            grades.push(parseInt(prompt("Enter a value in item no. " + (i + 1))));
          }
 document.write("LIST OF EVEN NUMBERS");
 document.write("<br><br>");
 for (i = 0; i < 10; i++) {
  if (grades[i] % 2 == 0){
  document.write(grades[i] + "<br>");
}
     }
 
 document.write("LIST OF ODD NUMBERS");
 document.write("<br><br>");
 for (i = 0; i < 10; i++) {
  if (grades[i] % 2 != 0){
  document.write(grades[i] + "<br>");
}
     }
   
</script>
</body>
</html>
 

No comments:

Post a Comment