repl.it
@PacoTaco/

REVIEW ON FUNCTION AND CLASSES

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
40
41
42
43
44
45
46
47
48
49
50
51
52
class Player{
  constructor(id){
  this.hands = 0;
  this.alive = true;
  this.id = id;
  }
  throw(){
    this.hand = Math.floor(1 + Math.random()*3);

  }
  toString(){
  console.log(this.id);
  console.log(this.hand);

  switch(this.hand){
    case 1 :
    console.log("rock")
    break;
    case 2 :
    console.log("paper")
    break;
    case 3 :
    console.log("scissor")
    break;
  }
  }


}


var numPlayer = 100;
var playerList = [];

for(var i = 0; i<= numPlayer; i++){
  var tempPlayer = new Player(i);
  playerList.push(tempPlayer);

}
function testLoopThru(){
  for(var i = 0; i < playerList.length - 1; i++){
    playerList[i].throw();
    playerList[i].toString();

  }


}
testLoopThru();


Fetching token
?