File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ import run from '../src/games/calc.js' ;
4+
5+ run ( ) ;
Original file line number Diff line number Diff line change 1+ import playGame from '../index.js' ;
2+
3+ const rules = 'What is the result of the expression?' ;
4+
5+ const calc = ( ) => {
6+ const firstNum = Math . floor ( Math . random ( ) * 50 ) + 1 ;
7+ const secondNum = Math . floor ( Math . random ( ) * 25 ) + 1 ;
8+ const operations = [ '+' , '-' , '*' ] ;
9+ const operation = operations [ Math . floor ( Math . random ( ) * 3 ) ] ;
10+ const expression = `${ firstNum } ${ operation } ${ secondNum } ` ;
11+ let correctAnswer = 0 ;
12+
13+ switch ( operation ) {
14+ case '+' :
15+ correctAnswer = firstNum + secondNum ;
16+ break ;
17+ case '-' :
18+ correctAnswer = firstNum - secondNum ;
19+ break ;
20+ case '*' :
21+ correctAnswer = firstNum * secondNum ;
22+ break ;
23+ default :
24+ break ;
25+ }
26+
27+ return [ expression , String ( correctAnswer ) ] ;
28+ } ;
29+
30+ export default ( ) => playGame ( rules , calc ) ;
Original file line number Diff line number Diff line change 1+ import playGame from '../index.js' ;
2+
3+ const rules = 'Answer "yes" if the number is even, otherwise answer "no".' ;
4+
5+ const askIsEven = ( ) => {
6+ const evenNum = Math . floor ( Math . random ( ) * 100 ) + 1 ;
7+ const correctAnswer = evenNum % 2 === 0 ? 'yes' : 'no' ;
8+ return [ evenNum , correctAnswer ] ;
9+ } ;
10+
11+ export default ( ) => playGame ( rules , askIsEven ) ;
You can’t perform that action at this time.
0 commit comments