Condition checking??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Arun Kannath
    New Member
    • Jun 2011
    • 1

    Condition checking??

    Code:
    <html>
    <body>
    
    <script type="text/javascript">
    var r=Math.random();
    if (r<0.5)
    {
    document.write("<a href='http://www.w3schools.com'>Learn Web Development!</a>");
    }
    else
    {
    document.write("<a href='http://www.refsnesdata.no'>Visit Refsnes Data!</a>");
    }
    </script>
    
    </body>
    </html>
    here pls explain me about the condition checked for switching two websites
    Last edited by Dormilich; Jun 13 '11, 03:13 PM. Reason: please use [CODE] [/CODE] tags when posting code
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It's checking the value of r, which is a random number. If it's less than 0.5 it uses the first address, if not, it uses the second address.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32668

      #3
      This randomly assigns half the people who open this page to see one of the addresses, and the other half the other. I expect the document.write bit is making up some further HTML for the remote browser, so the user would see either of two links in their new page, but I'm no web expert. The random bit is ensuring half the visitors see one version and the other half see the other though.

      Comment

      • Pradip Panchal
        New Member
        • Jun 2011
        • 1

        #4
        Hi Arun Follow this link once you get exactly idea about the Math.Random() Function...

        How to use the JavaScript Math.random function useful with round, ceiling, and floor.


        Hope This Will Help You..

        ~~Radhe

        Comment

        Working...