Using toggle buttons to filter Twitch feed results

Using toggle buttons to filter Twitch feed results
0

#1

Hi

I am currently working on the TwitchJSON API project and I think I am almost there with a reasonable solution. I have decided to use two toggle switches to filter down the results. If I want to see list of twitch accounts that are currently offline, then I would put the “offline” switch on. If I want to see list of twitch accounts that are online, then I would put the “online” switch on. Both to be on if I want to see whole list.

The offline button seems to filter down okay, but for some reason the Online toggle button is not working. In line 134 I use an If statement to check value of Online toggle button, and if “On” then to run code that will list any twitch accounts marked as online. But this if condition doesn’t seem to be hitting the mark…any ideas or suggestions would be warmly welcome! Thank you.

My code : http://codepen.io/vassblanc/pen/GreGqZ


#2

Line 123. I hope this is a typo:

html += onlineCh += offlineChecked;

#3

Thank you Jenovs. I had left that in as a debugging line to check that I was getting the correct values from the toggle buttons. This shows that both variables will show “on” when both toggle buttons are on, but this shouldnt effect the outcome of the if statement in line 134…


#4

Does your code work without line 123?


#5

Well yes it does! :smile:

Thank you for the subtle hint. Much appreciated :slight_smile:

Can you explain why that line would affect the rest of the code from working ? It seems that i was being naive to think that it was just harmless debugging line which would not affect anything else…
Thanks for your time.


#6

There is such thing as Operator Precedence.

+= has Associativity: right-to-left it means that your line gets evaluated from right side, i.e. it does

onlineCh += offlineChecked

first and only then

html += onlineCh

The question - What is the value of onlineCh after line 123?


#7

:open_mouth: it would have a value that is an amalgamation of both toggle button values! I see ! :slight_smile:

Thank you for the help. Much appreciated!