Results 1 to 4 of 4

Thread: Is It Possible To Create Such A Program?

  1. #1
    Join Date
    Nov 2008
    Location
    USA / Illinois / Morton
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Is It Possible To Create Such A Program?

    Is it possible to prompt a user for a number and write out a list of numbers to the user picked number and also say next to each one whether it's odd or even?
    Last edited by Tseng; 11-18-2008 at 01:14 PM. Reason: spelling

  2. #2
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Quote Originally Posted by Tseng View Post

    Is it possible to prompt a user for a number and write out a list of numbers to the user picked number and also say next to each one whether it's odd or even?
    Of course it's possible - your teacher wouldn't have asked you to do it otherwise.

    You're welcome in advance.

  3. #3
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here:
    Code:
    <script type="text/javascript">
    var num = prompt('Feed me a number!','');
    for(i=0;i<=num;++i){
      if((i/2) == Math.round(i/2)){
        document.write(i+" - Even<br />");
      } else {
        document.write(i+" - Odd<br />");
      }
    }
    </script>
    Jeremy | jfein.net

  4. #4
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Code:
    for(var i=0; i<=num; ++i)
     document.write(i + " - " + ( i&1 ? "Odd" : "Even") + "<br />");

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •