mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
- Create a function named
getFavsand set its contents toalert('clicked') - Create a variable
buttonand set it to a reference to our button by usingdocument.querySelector('button') - Add a click event listener to the button that calls
getFavs. Click the button and make sure it calls our alert. - Replace the alert with a new
favListvariable set to an empty array:[] - Create a const variable
inputsset to all of the inputs on the page.querySelectorAllwill help here - Iterate over all of the inputs using
for (const input of inputs) {} - For each iteration use an
ifstatement to check ifinput.checkedis equal to true - If the above tests passes, push the
input.parentNode.textContentonto thefavListarray. Pass that text intofavList.push()as the parameter to add it to the array - Outside of the for loop, use
document.querySelector('.favorites')to target the div at the bottom of the page. Set the div'stextContenttofavList.join(' '). This will join each of the foods together into a string separated by a space.