-
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
1 parent
75de257
commit 29e93ab
Showing
3 changed files
with
55 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
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,41 @@ | ||
|
||
import readlineSync from 'readline-sync'; | ||
|
||
|
||
const generateProgression = (length, step, start) => { | ||
const progression = []; | ||
for (let i = 0; i < length; i++) { | ||
progression.push(start + i * step); | ||
} | ||
return progression; | ||
}; | ||
|
||
const getRandomIndex = (length) => Math.floor(Math.random() * length); | ||
|
||
// Запуск игры | ||
const playProgressionGame = () => { | ||
console.log('What number is missing in the progression?'); | ||
|
||
const length = 10; // Длина прогрессии | ||
const step = Math.floor(Math.random() * 10) + 1; | ||
const start = Math.floor(Math.random() * 10); | ||
|
||
const progression = generateProgression(length, step, start); | ||
const hiddenIndex = getRandomIndex(length); | ||
const hiddenValue = progression[hiddenIndex]; | ||
|
||
progression[hiddenIndex] = '..'; | ||
|
||
console.log(`Question: ${progression.join(' ')}`); | ||
|
||
const userAnswer = readlineSync.question('Your answer: '); | ||
|
||
if (parseInt(userAnswer, 10) === hiddenValue) { | ||
console.log('Correct!'); | ||
} else { | ||
console.log(`'${userAnswer}' is wrong answer ;(. Correct answer was '${hiddenValue}'.`); | ||
console.log('Let\'s try again!'); | ||
} | ||
}; | ||
|
||
export default playProgressionGame; |
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