Answers for "rock paper scissors js"

3

rock paper scissors javascript

const tolowerUcFirst = v => v.charAt(0).toUpperCase() + v.slice(1).toLowerCase()

const answer = prompt(
  'Do you want to play Rock Paper Scissors? Type yes or no!'
)

if (answer && ['Y', 'YES'].includes(answer.toUpperCase())) {
  let board = ['ROCK', 'PAPER', 'SCISSORS']
  let answer = prompt('Rock, Paper, or Scissors?')

  if (board.includes(answer.toUpperCase())) {
    let them = board[Math.floor(Math.random() * 3)]
    let you = answer.toUpperCase()

    if (them === you) {
      console.log('draw', you, them)
      alert(`Draw, they choose ${tolowerUcFirst(them)} too!`)
    } else {
      // win rules
      if (
        // SCISSORS
        (you === 'SCISSORS' && them === 'PAPER') ||
        // PAPER
        (you === 'PAPER' && them === 'ROCK') ||
        // ROCK
        (you === 'ROCK' && them === 'SCISSORS')
      ) {
        console.log('you win', you, them)
        alert(`You win, they choose ${tolowerUcFirst(them)}!`)
      } else {
        console.log('you lose', you, them)
        alert(`You lose, they choose ${tolowerUcFirst(them)}!`)
      }
    }
  }
}
Posted by: Guest on August-28-2020
3

rock paper scissors

My Rock Paper Scissor game:
https://codepen.io/Lorenzo-SC/pen/ExgpPEO
Please give me a like if you appreciate :)
Posted by: Guest on January-08-2021
1

rock paper scissors

import random

print('Get ready for rock,paper,scissors')
user = input('Enter your element:')
element = ['I choose Rock', 'I choose Paper', 'I choose Scissors']
AI = random.choice(element)
print(AI)
# Ties
if AI == str('I choose Rock') and user == str('rock'):
    print('Its a tie')
if AI == str('I choose Paper') and user == str('paper'):
    print('Its a tie')
if AI == str('I choose Scissors') and user == str('scissors'):
    print('Its a tie')
# Rock AI
if AI == str('I choose Rock') and user == str('paper'):
    print('You won')
if AI == str('I choose Rock') and user == str('scissors'):
    print('You lost')
# Rock user
if AI == str('I choose Paper') and user == str('rock'):
    print('You lost')
if AI == str('I choose Scissors') and user == str('rock'):
    print('You won')
# Paper AI
if AI == str('I choose Paper') and user == str('rock'):
    print('You lost')
if AI == str('I choose Paper') and user == str('scissors'):
    print('You won')
# Paper user
if AI == str('I choose Rock') and user == str('paper'):
    print('You won')
if AI == str('I choose Scissors') and user == str('paper'):
    print('You lost')
# Scissors AI
if AI == str('I choose Scissors') and user == str('paper'):
    print('You lost')
if AI == str('I choose Scissors') and user == str('rock'):
    print('You won')
# Scissors user
if AI == str('I choose Paper') and user == str('scissors'):
    print('You won')
if AI == str('I choose Rock') and user == str('scissors'):
    print('You lost')


def restartgame():
    print('Get ready for rock,paper,scissors')
    user = input('Enter your element:')
    element = ['I choose Rock', 'I choose Paper', 'I choose Scissors']
    AI = random.choice(element)
    print(AI)
    # Ties
    if AI == str('I choose Rock') and user == str('rock'):
        print('Its a tie')
    if AI == str('I choose Paper') and user == str('paper'):
        print('Its a tie')
    if AI == str('I choose Scissors') and user == str('scissors'):
        print('Its a tie')
    # Rock AI
    if AI == str('I choose Rock') and user == str('paper'):
        print('You won')
    if AI == str('I choose Rock') and user == str('scissors'):
        print('You lost')
    # Rock user
    if AI == str('I choose Paper') and user == str('rock'):
        print('You lost')
    if AI == str('I choose Scissors') and user == str('rock'):
        print('You won')
    # Paper AI
    if AI == str('I choose Paper') and user == str('rock'):
        print('You lost')
    if AI == str('I choose Paper') and user == str('scissors'):
        print('You won')
    # Paper user
    if AI == str('I choose Rock') and user == str('paper'):
        print('You won')
    if AI == str('I choose Scissors') and user == str('paper'):
        print('You lost')
    # Scissors AI
    if AI == str('I choose Scissors') and user == str('paper'):
        print('You lost')
    if AI == str('I choose Scissors') and user == str('rock'):
        print('You won')
    # Scissors user
    if AI == str('I choose Paper') and user == str('scissors'):
        print('You won')
    if AI == str('I choose Rock') and user == str('scissors'):
        print('You lost')
    again = input('Would you like to play again')
    if again == str('yes'):
        restartgame()
    if again == str('no'):
        raise SystemExit(0)


again = input('Would you like to play again')
if again == str('yes'):
    restartgame()
if again == str('no'):
    raise SystemExit(0)
Posted by: Guest on November-09-2020

Code answers related to "rock paper scissors js"

Browse Popular Code Answers by Language