1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Javascrpit help

Discussion in 'Black Hat SEO' started by iNeedHalp, Nov 30, 2015.

  1. iNeedHalp

    iNeedHalp BANNED BANNED

    Joined:
    Nov 16, 2015
    Messages:
    15
    Likes Received:
    0
    I am new to Js and currently trying to learn....


    im trying to figure out why the following code prints out "paper" for anything above 1 if the "if else" says to print "scissors" if its >=.67




    var userChoice = prompt("Do you choose rock, paper of scissors?");
    var computerChoice = Math.random();
    if (computerChoice <= 0.33) {
    console.log("rock");
    } else if (computerChoice >= 0.67) {
    console.log("scissors");
    } else {
    console.log("paper");
    }
     
  2. randomzeus

    randomzeus Regular Member

    Joined:
    Apr 21, 2015
    Messages:
    360
    Likes Received:
    179
    Location:
    Bulgaria
    Home Page:
    What do u mean above 1? Math.random() returns a number between 0 and 1. So the above should print "Paper" if the random number is between 0.34 and 0.66. I don't understand the problem here mate?

    Regards!
     
    • Thanks Thanks x 1
  3. iNeedHalp

    iNeedHalp BANNED BANNED

    Joined:
    Nov 16, 2015
    Messages:
    15
    Likes Received:
    0
    yea i misread it, i get it now.. thx for the response i truly appreciate the help