I want to do switch toggle with plain Javascript with a function. But it seems the loop inside this function doesn\'t work since it only can detect the default state. The if