repl.it
Nodejs

No description

fork
loading
Files
  • index.js
  • Packager files
  • package-lock.json
  • package.json
index.js
1
2
3
4
5
6
7
8
9
console.log('pick a number from 1 to 3 to take from 21')
for (nimstot = 21, turn = 0; nimstot > 0; turn++) {
  if (turn % 2 == 0) {
    let num = parseInt(require('readline-sync').question("enter number:"));
    num < 1 || num > 3 || isNaN(num) ? turn-- : nimstot -= num;
  }
  else nimstot -= nimstot % 4 == 0 ? Math.ceil(Math.random() * 3) : nimstot % 4;
  console.log(nimstot <= 0 ? turn % 2 == 0 ? 'player won!!!' : 'computer won, :(' : nimstot + ' left')
}
?