Last active
August 29, 2015 14:10
-
-
Save kevlened/acd968314444fed7ea9c to your computer and use it in GitHub Desktop.
Semitone practice
This file contains hidden or 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
| var readline = require('readline'); | |
| var DIFFICULTY = 3; // Min is 1, Max is 11 | |
| var rl = readline.createInterface({ | |
| input: process.stdin, | |
| output: process.stdout | |
| }); | |
| var notes = ['A','Bb','B','C','Db','D','Eb','E','F','Gb','G','Ab']; | |
| var askNextNote = function() { | |
| var randIndex = Math.floor(Math.random() * 12); | |
| var randNote = notes[randIndex]; | |
| var randNext = (Math.floor(Math.random() * DIFFICULTY) % 12) + 1; | |
| var nextIndex = (randIndex + randNext) % 12; | |
| var nextNote = notes[nextIndex]; | |
| var showQ = function() { | |
| rl.question("What note is " + randNext + " semitones after " + randNote + "? ", function(answer) { | |
| var a = answer.trim().toLowerCase(); | |
| if(a === nextNote.toLowerCase()) { | |
| console.log(answer + " is correct"); | |
| askNextNote(); | |
| } | |
| else if(a === 'exit') { | |
| console.log("Finished"); | |
| rl.close(); | |
| } | |
| else { | |
| console.log("XXX: " + answer + " is incorrect :XXX"); | |
| showQ(); | |
| } | |
| }); | |
| }; | |
| showQ(); | |
| }; | |
| console.log("The current difficulty is: " + DIFFICULTY); | |
| console.log("The possible notes are: " + notes); | |
| askNextNote(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment