toggleSwitch.click and toggleSwitch keyup are almost 2 identical functions. Think of the way to refactor the code so that you do not have this repetition.