11import playGame from '../index.js' ;
22
3- const getRandomExpression = ( ) => {
4- const num1 = Math . floor ( Math . random ( ) * 100 ) + 1 ;
5- const num2 = Math . floor ( Math . random ( ) * 100 ) + 1 ;
6- const operations = [ '+' , '-' , '*' ] ;
7- const operation = operations [ Math . floor ( Math . random ( ) * operations . length ) ] ;
8- const expression = `${ num1 } ${ operation } ${ num2 } ` ;
9- let correctAnswer ;
10-
11- switch ( operation ) {
12- case '+' :
13- correctAnswer = num1 + num2 ;
14- break ;
15- case '-' :
16- correctAnswer = num1 - num2 ;
17- break ;
18- case '*' :
19- correctAnswer = num1 * num2 ;
20- break ;
21- }
22- return { question : expression , correctAnswer } ;
3+ const getRandomExpression = ( ) => {
4+ const num1 = Math . floor ( Math . random ( ) * 100 ) + 1 ;
5+ const num2 = Math . floor ( Math . random ( ) * 100 ) + 1 ;
6+ const operations = [ '+' , '-' , '*' ] ;
7+ const operation = operations [ Math . floor ( Math . random ( ) * operations . length ) ] ;
8+ const expression = `${ num1 } ${ operation } ${ num2 } ` ;
9+ let correctAnswer ;
10+
11+ switch ( operation ) {
12+ case '+' :
13+ correctAnswer = num1 + num2 ;
14+ break ;
15+ case '-' :
16+ correctAnswer = num1 - num2 ;
17+ break ;
18+ case '*' :
19+ correctAnswer = num1 * num2 ;
20+ break ;
21+ default :
22+ console . log ( 'Ошибка' ) ;
23+ }
24+ return { question : expression , correctAnswer } ;
2325} ;
2426
25- const playGameCalc = ( ) => {
26- const gameQuestion = 'What is the result of the expression?' ;
27- playGame ( getRandomExpression , gameQuestion ) ;
28- } ;
27+ const playGameCalc = ( ) => {
28+ const gameQuestion = 'What is the result of the expression?' ;
29+ playGame ( getRandomExpression , gameQuestion ) ;
30+ } ;
2931
30- export default playGameCalc ;
32+ export default playGameCalc ;
0 commit comments