File tree Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ brain-gcd:
1010 node bin/brain-gcd.js
1111brain-progression :
1212 node bin/brain-progression.js
13+ brain-prime :
14+ node bin/brain-prime.js
1315publish :
1416 npm publish --dry-run
1517lint :
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ import gamePrime from "../src/brainPrime.js" ;
4+
5+ gamePrime ( ) ;
Original file line number Diff line number Diff line change 99 "brain-even" : " bin/brain-even.js" ,
1010 "brain-calc" : " bin/brain-calc.js" ,
1111 "brain-gcd" : " bin/brain-gcd.js" ,
12- "brain-progression" : " bin/brain-progression.js"
12+ "brain-progression" : " bin/brain-progression.js" ,
13+ "brain-prime" : " bin/brain-prime.js"
14+
1315 },
1416 "scripts" : {
1517 "test" : " echo \" Error: no test specified\" && exit 1"
Original file line number Diff line number Diff line change 1+ import { getRandomNum } from "./brainEven.js" ;
2+ import { TheMotor } from "../index.js" ;
3+ const isPrime = ( num ) => {
4+ if ( num <= 1 ) {
5+ return false ;
6+ } ;
7+ for ( let i = 2 ; i <= Math . sqrt ( num ) ; i += 1 ) {
8+ if ( num % i === 0 ) {
9+ return false ;
10+ }
11+ } ;
12+ return true ;
13+ } ;
14+ const alert = "Answer 'yes' if given number is prime. Otherwise answer 'no'." ;
15+ const genRounds = ( ) => {
16+ const question = getRandomNum ( 1 , 1000 )
17+ const rightAnswer = isPrime ( question ) ? "yes" : "no" ;
18+ return [ question , rightAnswer ] ;
19+
20+ }
21+ const gamePrime = ( ) => {
22+ TheMotor ( alert , genRounds ) ;
23+ }
24+ export default gamePrime ;
25+
You can’t perform that action at this time.
0 commit comments