Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alert("Welcome to Rock, Paper or Scissors Game!\n\t ~Written By: Yehosua Selah~");
- var userName = prompt("Please enter your name");
- userName = userName.charAt(0).toUpperCase() + userName.slice(1);
- while(userName.length < 1 === true) {
- alert("Please don't leave it blank!");
- userName = prompt("Please enter your name");
- userName = userName.charAt(0).toUpperCase() + userName.slice(1);
- userName.length < 1 === false;
- };
- alert("Let's play Rock, Paper, or Scissors" + " " + userName + "!");
- var userAnswer = prompt("Are you ready?").toLowerCase();
- while ((userAnswer != "yes" && userAnswer != "no") == true){
- alert("Please answer either 'yes' or 'no' only!")
- userAnswer = prompt("Are you ready?").toLowerCase();
- ((userAnswer != "yes" && userAnswer != "no") == false)
- };
- if(userAnswer === "yes") {
- alert("Okay! Let's continue!");
- };
- if (userAnswer === "no") {
- alert("Don't worry! I won't cheat on you!");
- };
- var foeName = prompt(userName + ", " + "please create your enemy's name!");
- foeName = foeName.charAt(0).toUpperCase() + foeName.slice(1);
- while(foeName.length < 1 === true){
- alert("Please don't leave it blank!");
- foeName = prompt(userName + ", " + "please create your enemy's name!");
- foeName = foeName.charAt(0).toUpperCase() + foeName.slice(1);
- foeName.length < 1 === false;
- };
- alert("The game battle is between" + " \n\t" + userName + " " + "vs." + " " + foeName);
- alert("Are both players ready?");
- alert("Let the game begin!")
- var userChoice = prompt(userName + ", " + "do you choose rock, paper or scissors?").toLowerCase();
- while ( (userChoice != "rock" && userChoice != "paper" && userChoice != "scissors") === true ) {
- alert("Oh No!!! That's not a valid choice! \n\t\tChoose again!");
- ((userChoice != "rock" && userChoice != "paper" && userChoice != "scissors") === false )
- userChoice = prompt("Do you choose rock, paper or scissors?").toLowerCase()
- };
- var computerChoice = Math.random();
- if (computerChoice < 0.34) {
- computerChoice = "rock";
- } else if(computerChoice <= 0.67) {
- computerChoice = "paper";
- } else {
- computerChoice = "scissors";
- }
- var compare = function (choice1,choice2) {
- if (choice1 === choice2) {
- return alert("Draw game!");
- }
- else if (choice1 === "rock") {
- if (choice2 === "scissors") {
- return alert("Computer Chose Scissors! \n\t\tYou win!");
- }
- else
- {
- return alert("Computer Chose Paper! \n\tComputer wins!");
- }
- }
- else if (choice1 === "paper") {
- if (choice2 === "rock") {
- return alert("Computer Chose Rock! \n\tYou win!");
- }
- else
- {
- return alert("Computer Chose Scissors! \n\tComputer wins!");
- }
- }
- else if (choice1 === "scissors") {
- if (choice2 === "rock") {
- return alert("Computer Chose Rock! \n\tComputer wins!");
- }
- }
- else
- {
- return alert("Computer Chose Paper! \n\t\tYou win!");
- }
- };
- compare (userChoice, computerChoice);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement