I am trying to create a music game where I need to create a 3D array from a basic 2D array. The plan was to copy and paste the 2D array 4 times into the 3D array before changing it, as shown below:
var note3base = [
["C", "E", "G"],
["C#", "E#", "G#"],
["Db", "F", "Ab"],
["D", "F#", "A"],
["Eb", "G", "Bb"],
["E", "G#", "B"],
["F", "A", "C"],
["F#", "A#", "C#"],
["Gb", "Bb", "Db"],
["G", "B", "D"],
["Ab", "C", "Eb"],
["A", "C#", "E"],
["Bb", "D", "F"],
["B", "D#", "F#"],
["Cb", "Eb", "Gb"]
];
var note3 = new Array(4);
for (h=0;h<note3.length;h++){
note3[h] = note3base;
}
for (i=0;i<note3[0].length;i++){
note3[1][i][1] = flat(note3[1][i][1]);
note3[2][i][1] = flat(note3[2][i][1]);
note3[2][i][2] = flat(note3[2][i][2]);
note3[3][i][2] = sharp(note3[3][i][2]);
}
Now the problem is that the loop forseems to apply the method to each individual array (from 0 to 3).
The desired output for note 3 [0] [1] would be CEG, note 3 [1] [1] would be C Eb G, note [2] [1] would be C Eb Gb, note [3] [1] would be CEG #.
Any help is much appreciated!
I have included (working) sharp and flat methods below for reference:
function sharp(note){
var newnote;
if (note.charAt(1) == "#"){
newnote = note.replace("#", "x");
} else if (note.charAt(1) == "b"){
newnote = note.replace("b", "");
} else {
newnote = note + "#";
}
return newnote;
}
function flat(note){
var newnote;
if (note.charAt(1) == "#"){
newnote = note.replace("#", "");
} else {
newnote = note + "b";
}
return newnote;
}