Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Java to PHP

  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Java to PHP

    Can anyone help me convert this small script to php. Any help is greatly appreciated!


    <html>
    <head>
    <script type="text/javascript">
    function isEven_Odd() {
    for(i=0;i<=100;i++) {
    var value = Math.random()*100; //generates a random number between 1 and
    100.
    value = Math.floor(value); //converts value to a whole number.
    if (value%2 == 0){
    n_even = value;
    }else{
    n_odd = value;
    }
    }
    document.write(n_even + " " +"is an even number."+"<br>");
    document.write(n_odd + " " +"is an odd number.");
    }
    </script>
    </head>
    <body>
    <script type="text/javascript">

    isEven_Odd();

    </script>
    </body>
    </html>


    Thanks
    Tom

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    PHP Code:
    <html>
    <head>
    <?
    function isEven_Odd() {
    for(
    $i=0;$i<=100;$i++) {
    $value rand(1100); 

    if (
    $value%== 0){
    $n_even $value;
    }else{
    $n_odd $value;
    }
    }
    echo 
    "$n_even is an even number.<br>";
    echo 
    "$n_odd is an odd  number.<br>";
    }
    ?>
    </script>
    </head>
    <body>


    <?=isEven_Odd();?>


    </body>
    </html>
    Last edited by NancyJ; 04-27-2006 at 02:48 PM.

  • #3
    New Coder
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Thanks Nancy


  •  

    Posting Permissions

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