@gelizabeth
Posted
Hi Matthew, Great work with HTML and CSS!
For javascript - I've seen your code, here are some suggestions:
1.Select element, not its property because element can emit events. let checkBox = document.querySelector('#myonoffswitch');
-
Input, in this case checkbox, has special event -
change
when element is checked/unchecked.checkBox.addEventListener('change', myFunction());
-
In myFunction check
checkbox.checked
and change innerHTML of elements.function myFunction(){ if(checkbox.checked) { //change prices to year} else {//change prices to month} }
Hope this helps, If you have more questions I'll try to answer. Happy coding!
@Mattvp21
Posted
Youre solution worked! :D
Thanks for saving me alot of time!
Just a quick question: Why use the change event in this case instead of checking the boolean?
Thanks again,
Matt
@gelizabeth
Posted
@Mattvp21 you are welcome:)
If you check Boolean it will call your myFunction only once - when page is loaded, so you will not see any change; and you need to call it every time you click year/month switch.
@Mattvp21
Posted
@gelizabeth So I guess that would explain why checking the condition in the console worked but not in the code. Got it!