Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
var rock = "rock";

var paper = "paper";

var computerPick = null;

var d = Math.random() * 100

var sizzors = "Sizzors";

var pick = prompt("Please pick rock, paper or sizzors", "<Answer here>");

if(pick = "sizzors") {
 if( d < 33) {
    computerPick = "sizzors"
  }
  else if(d < 66){
    computerPick = "rock"
  }
  else{
    computerPick = "paper"
  };

  if(computerPick = "paper"){
      console.log("You Win!(they picked paper)")
  }else if(computerPick = "rock"){
      console.log("You Lost(They picked rock)")
  }else{
      console.log("It was a tie!(They picked sizzors)")
   };



  } else if(pick = "paper"){
      
 if( d < 33) {
    computerPick = "sizzors"
  }
  else if(d < 66){
    computerPick = "rock"
  }
  else{
    computerPick = "paper"
  };
  if(computerPick = "paper"){
      console.log("It was a tie!(They picked paper)")
  }else if(computerPick = "rock"){
      console.log("You Won!(They picked rock)")
  }else{
      console.log("You Lost!(They picked sizzors)")
   };
  



  }else if(pick = "rock"){
      if( d < 33) {
    computerPick = "sizzors"
  }
  else if(d < 66){
    computerPick = "rock"
  }
  else{
    computerPick = "paper"
  };


  if(computerPick = "paper"){
      console.log("You Lost!(They pickedpaper)")
  }else if(computerPick = "rock"){
      console.log("It was a tie!(They picked rock)")
  }else{
      console.log("You Won!(They picked sizzors)")
   };
  }else{
      console.log("You didnt pick rock paper or sizzors!")
  }


What I have tried:

I cant figure out whats wrong with it!
Posted
Updated 19-Jan-18 10:33am
v3

I have figured it out i dont need help anymore!
 
Share this answer
 
Your code have more problems than the one in title.
This code is wrong in a subtile way:
JavaScript
var d = Math.random() * 100
...
if( d < 33) {
	computerPick = "sizzors"
}
else if(d < 66){
	computerPick = "rock"
}
else{
	computerPick = "paper"
};

Odds are:
-sizzors 33%
-rock 33%
-paper 34%

This code is better:
JavaScript
var d = Math.random() * 3
...
if( d < 1) {
	computerPick = "sizzors"
}
else if(d < 2){
	computerPick = "rock"
}
else{
	computerPick = "paper"
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900