repl.it
@MNouri/

Rock, Paper, Sissor Game

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var rock = 0;
var paper = 1;
var sissor = 2;

var items = [rock, paper, sissor];
var result;
var ai = Math.floor(Math.random() * items.length);
var player;

function gamePlay (player){
  if (ai == 0 && player == 0){
    result = "Rock by AI, Draw";
  } else if (ai == 1 && player == 1){
    result = "Paper by AI, Draw";
  } else if (ai == 2 && player == 2){
    result = "Sissor by AI, Draw";
  }

  if (ai == 0 && player == 1){
    result = "AI picked rock, You win";
  } else if (ai == 1 && player == 2){
    result = "AI picked paper, You win";
  } else if (ai == 2 && player == 0){
    result = "AI picked sissor, You win";
  }

  if (ai == 0 && player == 2){
    result = "AI picked rock, You loose";
  } else if (ai == 1 && player == 0){
    result = "AI picked paper, You loose";
  } else if (ai == 2 && player == 1){
    result = "AI picked sissor, You win";
  }

  console.log(result);
}

gamePlay(2);