A garden tour booking button should stay unavailable until a visitor agrees to the meeting instructions. The checkbox controls whether the button can be used.
In HTML, disabled and checked are boolean attributes. Their presence means true, even if the markup says disabled="false"; only leaving the attribute out means false. In JavaScript, use the corresponding boolean properties: button.disabled and checkbox.checked. Assign true or false, not the strings "true" or "false". Changing button.disabled reflects in its HTML attribute, but changing a checkbox's current .checked state does not rewrite its default checked attribute. element.hasAttribute("disabled") reports whether the button attribute is present; unlike getAttribute, it returns a boolean. The checkbox's .checked property reports its current state, whereas getAttribute("checked") reads the original/default markup attribute and does not reliably track later clicks.
This is the first completed click/change interaction in this part of the course. addEventListener("change", updateBooking) asks the browser to call the function whenever the checkbox changes; the separate updateBooking() call sets the initial state before any interaction. Events get a dedicated section later. The working script.js updates both the control and a plain-language message:
const consent = document.querySelector("#tour-consent");
const reserve = document.querySelector("#reserve-tour");
const status = document.querySelector("#booking-status");
function updateBooking() {
reserve.disabled = !consent.checked;
status.textContent = reserve.hasAttribute("disabled")
? "Agree to the tour instructions first."
: "Tour booking is ready.";
}
consent.addEventListener("change", updateBooking);
updateBooking();
The initial call matters: without it, the message and control might disagree before anyone interacts. A native disabled button cannot receive a click, so no extra click guard is needed here.
Initially the button is disabled and the instruction appears. Check the box: the button becomes available and the message changes. Uncheck it to restore the disabled state. In index.html, try replacing disabled with disabled="false" and Run: the button is still disabled until the checkbox is checked. Restore the original markup afterward. Next, apply this pattern to another kind of sign-up.