Skip to content

Commit

Permalink
#1 implementation -#2 Add function toggleDrum in script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonaPiz committed Oct 9, 2023
1 parent 1e1b791 commit d807274
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion public/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,49 @@ let snares = new Array(16).fill(false);

let hiHats = new Array(16).fill(false);

let rideCymbals = new Array(16).fill(false);
let rideCymbals = new Array(16).fill(false);

/*2.
una funzione chiamata toggleDrumche accetta due argomenti: una stringa che rappresenta il nome
dell'array ( 'kicks', 'snares', 'hiHats'o 'rideCymbals') e un numero di indice. Questa funzione
dovrebbe capovolgere il valore booleano nell'array corretto all'indice specificato.
*/
const toggleDrum = (arrayName, index) => {
// verifichiamo che i valori di index siano validi
if(index < 0 || index > 16) {
return;
};

// toggle drum
switch (arrayName) {
case 'kicks':
if (kicks[index] === true) {
kicks[index] = false;
} else {
kicks[index] = true;
};
break;
case 'snares':
if (snares[index] === true) {
snares[index] = false;
} else {
snares[index] = true;
};
break;
case 'hiHats':
if (hiHats[index] === true) {
hiHats[index] = false;
} else {
hiHats[index] = true;
};
break;
case 'rideCymbals':
if (rideCymbals[index] === true) {
rideCymbals[index] = false;
} else {
rideCymbals[index] = true;
};
break;
default: return;
};
};

0 comments on commit d807274

Please sign in to comment.