Place the script after the example markup so its elements already exist.
const save = document.querySelector('button');
const status = document.querySelector('#status');
save.addEventListener('click', () => {
const next = save.getAttribute('aria-pressed') !== 'true';
save.setAttribute('aria-pressed', String(next));
status.textContent = next ? 'Saved' : 'Not saved';
});