Skip to content

Commit cf0e532

Browse files
committed
add src/games
1 parent cc96830 commit cf0e532

File tree

11 files changed

+25
-19
lines changed

11 files changed

+25
-19
lines changed

bin/brain-calc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
2-
import { calcGame } from '../games/calc-game.js'
2+
import { calcGame } from '../src/games/calc-game.js'
33

44
calcGame()

bin/brain-even.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
2-
import { evenGame } from '../games/even-game.js'
2+
import { evenGame } from '../src/games/even-game.js'
33

44
evenGame()

bin/brain-gcd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
2-
import { nodGame } from '../games/NOD-game.js'
2+
import { nodGame } from '../src/games/NOD-game.js'
33

44
nodGame()

bin/brain-prime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
2-
import { isPrimeGame } from '../games/prime-game.js'
2+
import { isPrimeGame } from '../src/games/prime-game.js'
33

44
isPrimeGame()

bin/brain-progression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
2-
import { progressionGame } from '../games/progression-game.js'
2+
import { progressionGame } from '../src/games/progression-game.js'
33

44
progressionGame()

games/NOD-game.js renamed to src/games/NOD-game.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { gamelogic } from '../src/index.js'
1+
import { gamelogic } from '../index.js'
22
import readlineSync from 'readline-sync'
3+
import { randomNum } from '../random-num.js'
34
const rules = 'Find the greatest common divisor of given numbers.'
45

56
function nod() {
6-
const number1 = Math.floor(Math.random() * (20))
7-
const number2 = Math.floor(Math.random() * (20))
7+
const number1 = randomNum
8+
const number2 = randomNum
89
console.log(`Question: ${number1} ${number2}`)
910
const stranswer = readlineSync.question('Your answer: ')
1011
const answer = parseInt(stranswer, 10)

games/calc-game.js renamed to src/games/calc-game.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { gamelogic } from '../src/index.js'
1+
import { gamelogic } from '../index.js'
22
import readlineSync from 'readline-sync'
3+
import { randomNum } from '../random-num.js'
34
const rules = 'What is the result of the expression?'
45
function calc() {
56
const operators = ['+', '-', '*']
67
const randomOperator = operators[Math.floor(Math.random() * operators.length)]
7-
const number1 = Math.floor(Math.random() * (9))
8-
const number2 = Math.floor(Math.random() * (10))
8+
const number1 = randomNum
9+
const number2 = randomNum
910
console.log(`Question: ${number1} ${randomOperator} ${number2}`)
1011
const stranswer = readlineSync.question('Your answer: ')
1112
const answer = parseInt(stranswer, 10)

games/even-game.js renamed to src/games/even-game.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { gamelogic } from '../src/index.js'
1+
import { gamelogic } from '../index.js'
22
import readlineSync from 'readline-sync'
3+
import { randomNum } from '../random-num.js'
34
const rules = 'Answer "yes" if the number is even, otherwise answer "no"'
45

56
export function isEven() {
6-
const number = Math.floor(Math.random() * (52))
7+
const number = randomNum
78
console.log(`Question: ${number}`)
89
const answer = readlineSync.question('Your answer: ')
910
let result

games/prime-game.js renamed to src/games/prime-game.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { gamelogic } from '../src/index.js'
1+
import { gamelogic } from '../index.js'
22
import readlineSync from 'readline-sync'
3+
import { randomNum } from '../random-num.js'
34
const rules = 'Answer "yes" if given number is prime. Otherwise answer "no"'
45

56
function isPrime(number) {
@@ -17,7 +18,7 @@ function isPrime(number) {
1718
return 'yes'
1819
}
1920
function primenumber() {
20-
const number = Math.floor(Math.random() * 100)
21+
const number = randomNum
2122
console.log(`Question: ${number}`)
2223
const answer = readlineSync.question('Your answer: ')
2324
let result = isPrime(number)

games/progression-game.js renamed to src/games/progression-game.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { gamelogic } from '../src/index.js'
1+
import { gamelogic } from '../index.js'
22
import readlineSync from 'readline-sync'
3+
import { randomNum } from '../random-num.js'
34
const rules = ('What number is missing in the progression?')
45

56
function progressionElem() {
6-
const start = Math.floor(Math.random() * 10)
7-
const step = Math.floor(Math.random() * 15)
7+
const start = randomNum
8+
const step = randomNum
89
let numbers = []
910
for (let i = 0; i <= (Math.floor(Math.random() * 6 + 5)); i++) {
1011
let elem = (start + i * step)
@@ -15,7 +16,7 @@ function progressionElem() {
1516

1617
function progression(seq) {
1718
seq = progressionElem()
18-
let index = Math.floor(Math.random() * seq.length)
19+
let index = randomNum * seq.length
1920
let result = seq[index]
2021
seq[index] = '..'
2122
console.log(`Question: ${seq.join(' ')}`)

0 commit comments

Comments
 (0)