For this lesson the goal was to have a list of checkboxes and check any boxes between two that the use clicked. So the use clicks checkbox 2 then shift clicks checkbox 4, checkbox 3 should also be checked. I tried working on the solution myself before finishing the video and seeing Wes’s solution. I got it working. But my solution is so horrible I’m not going to post it. I’ll simply describe it. My original solution uses three flags and six if statements while looping over the checkboxes. My solution was the same general pattern as Wes’s. Keep track of the last clicked checkbox and if the user clicks on a box while holding shift, run .forEach() on the checkbox node list and compare nodes.
Wes’s solution is a compact 14 lines if you make the loop if statements one-liners. My solution was 37 lines of spaghetti code.
The prepared solution was elegant and simple. After looking at it, it was obvious to be written that way. I need to work on simplifying my way of thinking. I’ve been programming for roughly five years and still think up overly complex beasts for something that could be solved with half as much time and half as much code. Maybe I’ll starting working through logic puzzles.