DEV Community

Discussion on: Is it possible to write this code in a simpler way?

Collapse
 
nickytonline profile image
Nick Taylor • Edited

You actually don't need an off class. That can just be part of the bulb class. Then all you need to do is toggle the on class. Here's a fork of your codepen with the changes. I also, for fun, change the switch text based on the status.

If something isn't clear let me know and I can clarify.

Also, if you want to embed a codepen you can do the following for example:

{%codepen https://codepen.io/nickytonline/pen/OeLVqg %}

Collapse
 
nanythery profile image
Nadine M. Thêry

Absolutely right. Thanks for your help and advice :)