main.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
53
54
55
function score( dice ) {
  let points = 0;
  const threeOnes = dice.filter((item) => { return item === 1; });
  if (threeOnes.length === 3) {
    points += 1000;
  } else if(threeOnes.length === 1) {
    points += 100;
  } else if(threeOnes.length === 2) {
    points += 200;
  }
  const threeSix = dice.filter((item) => { return item === 6; });
  if (threeSix.length === 3) {
    points += 600;
  }
  const threeFives = dice.filter((item) => { return item === 5; });
  if (threeFives.length === 3) {
    points += 500;
  } else if(threeFives.length === 1) {
    points += 50;
  } else if(threeFives.length === 2) {
    points += 100;
  }
  const threeFours = dice.filter((item) => { return item === 4; });
  if (threeFours.length === 3) {
    points += 400;
  }
  const threeThrees = dice.filter((item) => { return item === 3; });
  if (threeThrees.length === 3) {
    points += 300;
  }
  const threeTwos = dice.filter((item) => { return item === 2; });
  if (threeTwos.length === 3) {
    points += 200;
  }
  //console.dir(dice);
  return points;
}

console.log(`score ${score( [2, 3, 4, 6, 2] )} === 0 `);

console.log(`score ${score( [4, 4, 4, 3, 3] )} === 400 `);

console.log(`score ${score( [2, 4, 4, 5, 4] )} === 450 `);

console.log(`score ${score( [1, 2, 1, 1, 4] )} === 1000 `);

console.log(`score ${score( [2, 2, 2, 3, 4] )} === 200 `);

console.log(`score ${score( [2, 3, 3, 3, 4] )} === 300 `);

console.log(`score ${score( [2, 4, 4, 3, 4] )} === 400 `);

console.log(`score ${score( [5, 5, 5, 3, 4] )} === 500 `);

console.log(`score ${score( [6, 6, 6, 3, 4] )} === 600 `);
Native Browser JavaScript