SASS Toggles HW
Popcorn Hack: Fill in the Blanks
- The checkbox on a toggle keeps track of whether it is on or off.
- The slider is the visible part of the toggle that changes color when it is turned on.
- The
.switchclass controls the toggle’s position, size, padding, and alignment. - The border-radius property makes the slider have rounded edges.
- The
&:beforeclass dictates the white circle of the toggle.
Challenge
Popcorn Hack: the finished toggle with its checkbox, slider, and label. Press Run and click it.
Find the Bug: The Missing Class
The broken toggle was missing the ocs__toggle-track class, the span that draws the visible track. aria-hidden="true" tells screen readers to skip it since it is only decoration.
Challenge
Find the Bug: add the missing class so the toggle track shows up. Press Run.
Homework Hack: Study Settings Panel
Four toggles, each with its own purpose and label. JavaScript reads .checked on each one and updates the page, a live counter shows how many are on, and three toggles drive real features on the page (a shown/hidden tip, a dark preview box, and larger text). Comments explain what I learned.
Challenge
Homework Hack: build your own toggles and use JavaScript to react to them. Press Run and flip each toggle.
How it meets each requirement
- At least 3 toggles, each with its own label and purpose: 4 toggles (study tip, dark preview, large text, homework reminders).
- JavaScript checks each on/off state:
.checkedis read on every toggle insideupdate(). - Section showing how many are on, updating live:
Toggles turned on: N of 4, refreshed by thechangeevent. - At least 2 comments showing understanding: the comments explain
.checked, why oneupdate()function redraws everything, and that counting checked toggles is an AP CSP conditional. - Above and beyond: three toggles trigger real features (show/hide the tip, dark preview, large text) instead of only changing their own look.
The lesson’s “Customize the Toggle” challenge has a starter inside its editor, so it isn’t reproduced here.