Игра: Камень, ножницы, бумага

Post Reply
  • Author
  • Message
Offline
User avatar
Admin
Posts: 56
Joined: 31 Oct 2013, 13:36
Contact:

Игра: Камень, ножницы, бумага

Post by faridmmv » 15 Apr 2016, 18:22

Code: Select all

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice <= 0.34) 
{
	computerChoice = "rock";
} 
else if(0.34 < computerChoice <= 0.67) 
{
	computerChoice = "paper";
} 
else 
{
	computerChoice = "scissors";
} 
console.log("Computer choose: " + computerChoice);
console.log("You choose: " + userChoice);

var compare = function(choice1, choice2)
{
  if(choice1 === choice2)
  {
      return "The result is a tie!";
  }
  else if (choice1 !== "rock" && choice1 !== "paper" && choice1 !== "scissors") // Если вы наберете при запросе непредусмотренное функцией слово
  {
      return "Please choose paper, rock or scissors with lowercase letter";
  }
  else if (choice1 === "rock")
  {
      if(choice2 === "scissors")
      {
          return "Rock Wins";
      }
      else
      {
          return "Paper Wins";
      }
  }
  else if(choice1 === "paper")
  {
      if(choice2 === "rock")
      {
          return "Paper Wins";
      }
      else
      {
          return "Scissors Wins";
      }
  }
  else if (choice1 === "scissors")
  {
      if(choice2 === "rock")
      {
          return "Rock Wins";
      }
      else
      {
          return "Scissors Wins";
      }
  }
};
compare(userChoice, computerChoice);
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest