I'm working on a program that, before it can do anything else, must be able to convert numbers into other numbers. The program only works with numbers 0 through 11 (representing music notes), so anything greater or less than that must be converted to a number between 0 and 11. But when I run my function, it returns undefined for a lot of numbers.
const TET = 12;
const Notes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
function NoteConverter(note) {
const doubled = TET * 2;
const tripled = TET * 3;
for (index in Notes) {
if (note == index) {
return index;
} else if (note == index + TET || note == index - TET) {
return index;
} else if (note == index + doubled || note == index - doubled) {
return index;
} else if (note == index + tripled || note == index - tripled) {
return index;
}
}
}
When I run the function using 15 as the number to be converted, I get undefined instead of 3, which it should convert to.
I've been trying to figure out what I'm doing wrong but can't. Any help?