summaryrefslogtreecommitdiff
path: root/notes.js
blob: b80188c46e4c13c8e774f3751871dfbde4d2f926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { createInterface } from 'node:readline/promises';

const noteList = [
  ["do", "tidi"],
  ["dodi", "rebe"],
  ["re"],
  ["redi", "mibe"],
  ["mi", "fabe"],
  ["fa", "midi"],
  ["fadi", "sobe"],
  ["so"],
  ["sodi", "labe"],
  ["la"],
  ["ladi", "tibe"],
  ["ti", "dobe"],
];

const MAX_INTERVAL = 4;

const randomIndex = (array) => Math.floor(Math.random() * array.length);
const randomElement = (array) => array[randomIndex(array)];

const readline = createInterface({
	input: process.stdin,
	output: process.stdout,
});

const makeTest = async () => {
	const startingNoteIndex = randomIndex(noteList);
	// random number between -$MAX_INTERVAL --- +$MAX_INTERVAL
	const getInterval = () => Math.round((Math.random() * MAX_INTERVAL * 2) - MAX_INTERVAL);
	const interval = getInterval()
	const displayInterval = interval > 0 ? `+${interval}`: interval;
	const displayStartingNote = randomElement(noteList[startingNoteIndex])
	// 11 + 4 should yield 3
	const targetIndex = (startingNoteIndex + interval) % noteList.length
	const acceptedAnswers = noteList.at(targetIndex);

	performance.mark('start')
	const response = await readline.question(`${displayStartingNote} ${displayInterval} `)
	try {
		if (acceptedAnswers.includes(response)) {
			performance.mark('end')
			const { duration } = performance.measure('time', 'start', 'end')
			console.log('correct!', `Took ${Math.round(duration)/1000}s`);
		} else {
			console.log('wrong! should be:', acceptedAnswers.join(', or '))
		}
	} catch (e) {
		console.log('error!');
		console.log({ startingNoteIndex, interval, targetIndex })
	}
}

while (true) {
	await makeTest()
}