Popcorn Hack: Fill in the Blanks

  1. The checkbox on a toggle keeps track of whether it is on or off.
  2. The slider is the visible part of the toggle that changes color when it is turned on.
  3. The .switch class controls the toggle’s position, size, padding, and alignment.
  4. The border-radius property makes the slider have rounded edges.
  5. The &:before class dictates the white circle of the toggle.

Challenge

Popcorn Hack: the finished toggle with its checkbox, slider, and label. Press Run and click it.

Lines: 1 Characters: 0
UI Output

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.

Lines: 1 Characters: 0
UI Output

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.

Lines: 1 Characters: 0
UI Output

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: .checked is read on every toggle inside update().
  • Section showing how many are on, updating live: Toggles turned on: N of 4, refreshed by the change event.
  • At least 2 comments showing understanding: the comments explain .checked, why one update() 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.