Results 1 to 2 of 2

Thread: Math.floor with a While loop

Hybrid View

  1. #1
    Join Date
    Jul 2013

    Question Math.floor with a While loop

    I am learning javascript and I cant understand why the loop stop if there is not any part of the loop that says "false" (that means the loop have to end). Math.floor(); returns the high integer value, and when is used with a (Math.random() * 2) it returns 1 or 0 . So Can anybody help me to understand why this? http://www.webdeveloper.com/forum/im...s/confused.gif

    var moneda = Math.floor(Math.random() * 2);
    console.log("ˇCara! Lanzando de nuevo...");
    var moneda = Math.floor(Math.random() * 2);
    console.log("ˇSello! Lanzamiento concluido.");

  2. #2
    Join Date
    Jul 2013
    1 evaluates to true and 0 evaluates to false, so whenever moneda is 0, the loop ends.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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