# Rocks paper scissors game

**URL:** <https://discourse.mozilla.org/t/rocks-paper-scissors-game/65514>\
**Category:** Learn\
**Created:** [August 11, 2020, 12:02pm UTC](https://discourse.mozilla.org/t/rocks-paper-scissors-game/65514 "2020-08-11T12:02:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan\_Salerno](https://avatars.discourse-cdn.com/v4/letter/j/3da27b/32.png) [@Juan\_Salerno](https://discourse.mozilla.org/u/Juan_Salerno)\
**Post date:** [August 11, 2020, 12:02pm UTC](https://discourse.mozilla.org/t/rocks-paper-scissors-game/65514/1 "2020-08-11T12:02:11Z")

</div>

Hi, I had to build a simple rock paper scissors game on Javascript for an assignment. Still I’m not able to make it work. Could someone give me a hint on where it is failing? Code below.

let playerPlay = prompt(`Rock, paper or scissors`)  
const choices = [`null`, `rock`, `paper`, `scissors`];  
let number;  
let play;  
let result;  
let value;  
function computerPlay(choices, number, play, result){  
number = (Math.floor(Math.random()\*3)+1);  
play = choices[number];  
result= play;  
return result;  
}  
value = computerPlay(choices, number, play, result)  
console.log(value)

let computerScore = 0;  
let playerScore = 0;

if (playerPlay.toLowerCase() == `rock` && (value == `rock`){  
console.log (`It's a tie` )  
console.log (`Player score =` playerScore)  
console.log (`Computer score =` computerScore)  
}  
else if (playerPlay.toLowerCase() == `rock` && (value == `paper`){  
console.log (`Computer wins`)  
computerScore++  
console.log (`Player score =` playerScore)  
console.log (`Computer score =` computerScore)  
}  
else if (playerPlay.toLowerCase() == `rock` && (value == `scissors`){  
console.log (`Player wins`)  
playerScore++  
console.log (`Player score =` playerScore)  
console.log (`Computer score =` computerScore)  
}  
else if (playerPlay.toLowerCase() == `paper` && (value == `rock`){  
console.log (`Player wins`)  
playerScore++  
console.log (`Player score =` playerScore)  
console.log (`Computer score =` computerScore)  
}  
else if (playerPlay.toLowerCase() == `paper` && (value == `paper`){  
console.log (`It's a tie` )  
console.log (`Player score =` playerScore)  
console.log (`Computer score =` computerScore)  
}  
else if (playerPlay.toLowerCase() == `paper` && (value == `scissors`){  
console.log (`Computer wins`)  
computerScore++  
console.log (`Player score =` playerScore)  
console.log (`Computer score =` computerScore)  
}  
else if (playerPlay.toLowerCase() == `scissors` && (value == `rock`){  
console.log (`Computer wins`)  
computerScore++  
console.log (`Player score =` playerScore)  
console.log (`Computer score =` computerScore)  
}  
else if (playerPlay.toLowerCase() == `scissors` && (value == `paper`){  
console.log (`Player wins`)  
playerScore++  
console.log (`Player score =` playerScore)  
console.log (`Computer score =` computerScore)  
}  
else (playerPlay.toLowerCase() == `scissors` && (value == `scissors`){  
console.log (`It's a tie` )  
console.log (`Player score =` playerScore)  
console.log (`Computer score =` computerScore)  
}

---

<div class="post-metadata">

**Author:** ![Rafael\_Green](https://avatars.discourse-cdn.com/v4/letter/r/74df32/32.png) [@Rafael\_Green](https://discourse.mozilla.org/u/Rafael_Green)\
**Post date:** [August 11, 2020, 12:32pm UTC](https://discourse.mozilla.org/t/rocks-paper-scissors-game/65514/2 "2020-08-11T12:32:37Z")

</div>

Can you please put your code into an online shareable editor such as [CodePen](https://codepen.io/), [jsFiddle](https://jsfiddle.net/), or [Glitch](https://glitch.com/)?  
It’s hard to read it like that…

---

<div class="post-metadata">

**Author:** ![Juan\_Salerno](https://avatars.discourse-cdn.com/v4/letter/j/3da27b/32.png) [@Juan\_Salerno](https://discourse.mozilla.org/u/Juan_Salerno)\
**Post date:** [August 11, 2020, 4:45pm UTC](https://discourse.mozilla.org/t/rocks-paper-scissors-game/65514/3 "2020-08-11T16:45:36Z")

</div>

on codepen i get an error “Sorry you cannot post a link to that host.”.  
[https://jsfiddle.net/jcito14/wnje2br9/4/](https://jsfiddle.net/jcito14/wnje2br9/4/)

---

<div class="post-metadata">

**Author:** ![Rafael\_Green](https://avatars.discourse-cdn.com/v4/letter/r/74df32/32.png) [@Rafael\_Green](https://discourse.mozilla.org/u/Rafael_Green)\
**Post date:** [August 11, 2020, 4:57pm UTC](https://discourse.mozilla.org/t/rocks-paper-scissors-game/65514/4 "2020-08-11T16:57:22Z")

</div>

You have few syntax errors (follow the red dots in the left to the code in jsfiddle):  
In the if statements you have to surround the condition with rounded parentheses.  
For example,  
replace this:

```auto
if (playerPlay.toLowerCase() == `rock`) && (value == `rock`){

```

with:

```auto
if ((playerPlay.toLowerCase() == `rock`) && (value == `rock`)){

```

In addition, the syntax for strings concatenation is to use the plus character (`+`).  
For example:

```auto
let name = firstName + " " + lastName;

```

In your code, replace this:

```auto
console.log (`Player score =` playerScore)

```

with:

```auto
console.log (`Player score =` + playerScore)

```

also, its better to put “;” at the end of every statement.

I see that you use backticks for strings (```). It’s used for string interpolation in javascript. If you don’t use string interpolation it’s better to use quotes (` '`) or double quotes (`"`) for string literals.

One more comment is about the equality test. In general it’s better to use the `===` operator which compares the types and the values of it’s operands. Read more on it here: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality\_comparisons\_and\_sameness](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness)

One more tip is to start with few lines of code that works, test it and then add few more and test again, etc…

---

<div class="post-metadata">

**Author:** ![drgaud1](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@drgaud1](https://discourse.mozilla.org/u/drgaud1)\
**Post date:** [August 15, 2020, 3:07pm UTC](https://discourse.mozilla.org/t/rocks-paper-scissors-game/65514/5 "2020-08-15T15:07:30Z")

</div>

I have been taking a look over the script you posted, and I would say it is has its fair number of errors, which would prevent from JS from executing it. Like what @Rafael_Green was saying about using the correct syntax in all the right places.  
I would like to mention that this would also apply to strings in concole.logs(). please remember to check () {} [] ‘’.  
I honestly feel like my english teacher saying go back and punctuate it properly but really thats what your script needs is proper punctuation and syntax.

If you want or ever need help please do join our [Discord Server](https://discord.gg/whxbN9g)
