jeudi 17 octobre 2019

Correct addition of OR logical operator

I am using a script for inputting musical note selection (C, C#, etc) via checkboxes to find the name of the chord. With one octave it works perfectly.

I have 12 checkboxes with the following string as an example:

 if(cb[0].checked==true&&cb[1].checked==false&&cb[2].checked==false&&cb[3].checked==false&&cb[4].checked==true&&cb[5].checked==false&&cb[6].checked==false&&cb[7].checked==true&&cb[8].checked==false&&cb[9].checked==false&&cb[10].checked==false&&cb[11].checked==false) { alert('C'); }

This works fine when boxes C0, C4 and C7 are checked, and of course not when any other combination is checked.

Now, I want to add an extra octave. I've added a 13th box (C12) as an optional alternative to C0.

I tried adding the || operator as follows:

 if(cb[0].checked==true||cb[12]==true&&cb[1].checked==false...

but this doesn't work.

Strangely, just adding box C12 to the page without changing the script string at all, when I select boxes C12, C4 and C7 I get the result alert 'G♯/A♭m', which I should get only for this string:

else if(cb[8].checked==true&&cb[9].checked==false&&cb[10].checked==false&&cb[11].checked==true&&cb[0].checked==false&&cb[1].checked==false&&cb[2].checked==false&&cb[3].checked==true&&cb[4].checked==false&&cb[5].checked==false&&cb[6].checked==false&&cb[7].checked==false) { alert('G♯/A♭m'); } 

which I don't understand, as that string contains no cb[12] and only 2 of the 3 'true' checkboxes required.

Is there a correct way I can add this '||cb[12]==true' thread so that either C0 or C12 get the same result?

Thanks for reading this long question! Any advice appreciated.




Aucun commentaire:

Enregistrer un commentaire