mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
Exercise
- Create a function named
getFavs. Inside, runalert('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 the alert is displayed. - Replace the
alertcall with a newfavListvariable 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) {} - In each iteration, use an
ifstatement to check ifinput.checkedis equal to true - If the above tests passes, push the
input.parentNode.textContentonto thefavListarray by passing the text as a parameter tofavList.push()(`push is a built-in array method.) - 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.