-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env node | ||
|
||
import brainGames from './brain-games.js'; | ||
import { progressionGame } from '../src/games/index.js'; | ||
|
||
brainGames.startGame(progressionGame, 'What number is missing in the progression?'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as evenGame } from './evenGame.js'; | ||
export { default as calcGame } from './calcGame.js'; | ||
export { default as gcdGame } from './gcdGame.js'; | ||
export { default as progressionGame } from './progressionGame.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { askQuestion, getAnswer, getResponseAfterRound } from '../cli.js'; | ||
|
||
export default () => { | ||
const start = Math.round(Math.random() * 30); | ||
const step = Math.round(Math.random() * 20); | ||
const length = 10; | ||
|
||
const progression = Array(length).fill(start).map((value, index) => start + index * step); | ||
const targetIndex = Math.floor(Math.random() * length); | ||
const copyProgression = [...progression]; | ||
|
||
copyProgression[targetIndex] = '..'; | ||
|
||
const questionText = copyProgression.join(' '); | ||
|
||
askQuestion(questionText); | ||
|
||
const userAnswer = getAnswer('Your answer: '); | ||
const rightAnswer = progression[targetIndex]; | ||
|
||
const isUserRight = Number(userAnswer) === rightAnswer; | ||
const resultString = getResponseAfterRound(isUserRight, userAnswer, rightAnswer); | ||
|
||
console.log(resultString); | ||
|
||
return isUserRight; | ||
}; |