We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1f888f6 commit e63526dCopy full SHA for e63526d
bin/brain-prime.js
@@ -0,0 +1,5 @@
1
+#!/usr/bin/env node
2
+
3
+import run from '../src/games/prime.js';
4
5
+run();
src/games/prime.js
@@ -0,0 +1,23 @@
+import playGame from '../index.js';
+const rules = 'Answer "yes" if given number is prime. Otherwise answer "no".';
+const askIfPrime = () => {
6
+ const num = Math.floor(Math.random() * 100) + 1;
7
+ let divisors = 1;
8
+ let correctAnswer = '';
9
10
+ for (let i = 2; i <= num; i += 1) {
11
+ if (num % i === 0) {
12
+ divisors += 1;
13
+ if (divisors === 3) {
14
+ break;
15
+ }
16
17
18
+ correctAnswer = divisors === 2 ? 'yes' : 'no';
19
20
+ return [num, correctAnswer];
21
+};
22
23
+export default () => playGame(rules, askIfPrime);
0 commit comments