1+ import { TheMotor } from "../index.js" ;
2+ import { getRandomNum } from "./brainEven.js" ;
3+ const alert = 'What is the result of the expression?' ;
4+ const operations = ( ) => {
5+ const maxVal = 30 ;
6+ const minVal = 1 ;
7+ const firstNum = getRandomNum ( minVal , maxVal ) ;
8+ const secondNum = getRandomNum ( maxVal , maxVal ) ;
9+ const ops = [ "+" , "-" , "*" ] ;
10+ const minIndex = 0 ;
11+ const MaxIndex = ops . length - 1 ;
12+ const randomOp = ops ( getRandomNum ( minIndex , MaxIndex ) ) ;
13+ return `${ firstNum } ${ randomOp } ${ secondNum } `
14+ }
15+ const StartValueOPS = ( exs ) => {
16+ const convert = exs . split ( ' ' ) ;
17+ const num1 = + convert [ 0 ] ;
18+ const num2 = + convert [ convert . length - 1 ] ;
19+ const ops = convert [ 1 ] ;
20+ let result = 0 ;
21+
22+ switch ( ops ) {
23+ case '+' : result = num1 + num2 ;
24+ break ;
25+ case '-' : result = num1 - num2 ;
26+ break ;
27+ case '*' : result = num1 * num2 ;
28+ break ;
29+ default : throw new Error ( `Unknown order state: '${ exs } '!` ) ;
30+ }
31+
32+ return result ;
33+ }
34+ const gameCalc = ( ) => {
35+ const ops = operations ( ) ;
36+ const rightAnswer = StartValueOPS ( ops ) ;
37+ return [ ops , rightAnswer ] ;
38+ }
39+ const ReadyGameCalc = ( ) => {
40+ TheMotor ( gameCalc , alert )
41+ }
42+ export default ReadyGameCalc ;
0 commit comments