Skip to content

Instantly share code, notes, and snippets.

@kevlened
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save kevlened/acd968314444fed7ea9c to your computer and use it in GitHub Desktop.

Select an option

Save kevlened/acd968314444fed7ea9c to your computer and use it in GitHub Desktop.
Semitone practice
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