rock paper scissors javascript

Solutions on MaxInterview for rock paper scissors javascript by the best coders in the world

showing results for - "rock paper scissors javascript"
Maria
05 Feb 2019
1const tolowerUcFirst = v => v.charAt(0).toUpperCase() + v.slice(1).toLowerCase()
2
3const answer = prompt(
4  'Do you want to play Rock Paper Scissors? Type yes or no!'
5)
6
7if (answer && ['Y', 'YES'].includes(answer.toUpperCase())) {
8  let board = ['ROCK', 'PAPER', 'SCISSORS']
9  let answer = prompt('Rock, Paper, or Scissors?')
10
11  if (board.includes(answer.toUpperCase())) {
12    let them = board[Math.floor(Math.random() * 3)]
13    let you = answer.toUpperCase()
14
15    if (them === you) {
16      console.log('draw', you, them)
17      alert(`Draw, they choose ${tolowerUcFirst(them)} too!`)
18    } else {
19      // win rules
20      if (
21        // SCISSORS
22        (you === 'SCISSORS' && them === 'PAPER') ||
23        // PAPER
24        (you === 'PAPER' && them === 'ROCK') ||
25        // ROCK
26        (you === 'ROCK' && them === 'SCISSORS')
27      ) {
28        console.log('you win', you, them)
29        alert(`You win, they choose ${tolowerUcFirst(them)}!`)
30      } else {
31        console.log('you lose', you, them)
32        alert(`You lose, they choose ${tolowerUcFirst(them)}!`)
33      }
34    }
35  }
36}
queries leading to this page
most efficient rock paper scissors javascriptrock paper scissors using only javascriptmake rock paper scissors javascriptrock paper scissors javascript setrock paper scissors with javascriptjavascript rock paper scissors tutorialjs code for rock paper scissorsrock 2c paper 2c scissors jspaper scissors rock javascriptjs paper scissors rockrock 2c paper 2c scissors game in javascriptcode for rock paper scissors in javascriptrock paper scissors recurvsion javascriptrock paper scissors game javascript cssrocks paper scissors javascriptjs rock paper scissors object working rock paper scissors jshow to keep score dom javascript rock paper scissorsrock paper scissors function javascripyrock 2c paper scissors javascriptrock paper scissors javascript codehow to approach paper rock scissors javascriptrock paper scissors javascript with usersrock paper scissors javascriptjavascript rock paper scissors all possible solutionsrock paper scissors in js demorock paper scissors javascript toy problemjavascript rock paper scissors browserrock paper scissors boot stripes html javascriptrock paper scissors pure javascriptrock paper scissors javascript 4khow to make a simple rock paper scissors game in javascriptjavascript rock paper scissors rock paper scissors javascript htmlhow to make a rock paper scissors game in javascriptrock 2c paper scissors code javascriptgenerate rock paper scissors javascriptinstructions for rock paper scissors game javascriptrock paper scissors project javascriptrock paper scissor jshow to make a simple vanilla javascript rock paper scissorsjavascript rock paper scissors gamerock paper scissors in only java scriptpaper rock scissors javascriptrock paper scissors logic jsrock paper scissors html css javascripthow to make rock paper scissors in javascriptrock 2c paper 2c scissors code jsrock paper scissors function jsjavascript rock paper scissors easyrock paper scissors all outcomes javascriptjavascript rockcreate rock paper scissors javascript beginnersrock paper scissors game javascript coderock paper scissors javascript messagerock paper scissors program javascriptrock paper scissors how to play javascriptrock paper scissors javascript functionalrock paper scissors js tutorialrock paper scissors js functioncode rock paper scissors only in javascriptrock paper scissors js gamerock paper scissors image javascriptrock paper scissors javascript projectrock paper scissors game javascriptrock paper scissors jsrock paper scissors javascript code dommake rock paper scissors game javascriptrock paper scissors in java scripthow to move a rock solution javascriptrock paper scissors javascript outlinejavascript rock paper scissors caserock paper scissors in javascriptrock paper scissors set add javascripthow to create a rock paper scissors game in jsrock papaer scissors javascriptrock paper scissors vanilla javascript tutorialsimple rock paper scissors game javascriptrock paper scissors jsrock paper scissors vanilla javascriptrock paper scissors javascript tutorialhow do i do the rock paper scissors on javascriptrock paper scissors function javascriptrock paper scissors javascript using arrayshow to computer generate rock paper scissors in javascriptrock paper scissors html javascriptrock paper scissors code jscreate rock paper scissors javascripthow to create rock paper scissors in javascriptrock paper scissors in jsrock paper scissors javascript helprock 2c paper scissors javascript onlyjs rock paper scissorsproblem rock paper scissors javascripthow to code rock paper scissors jsrock paper sciccors javascript gamerock paper scissors game in javascriptjavascript rock paper scissors game instructionsbuilding rock 2c paper 2c scissors in javascripthow to make a rock paper scissors game in jsrock paper scissorsa jsrock 2c paper 2c scissors game javascriptbuild a rock paper scissors game jsrock paper scissors game jsrock paper sicors jswhat is rock paper scissors in javascriptrock paper scissors logic javascriptrock 2c paper 2c scissors function javascriptrock 2c paper scissors algorithm javascriptrock paper scissors algorithm javascriptjs code for rock paper scissors for beginnersrock paper scissors code javascriptbest way to solve rock paper scissors javascriptsimple rock paper scissors javascriptrock scissors paper javascriptrockpaperscissors jsrock paper scissors javascript