Complete the code to show an alert when the button is clicked.
document.getElementById('myButton').addEventListener('click', function() { alert([1]); });
The alert function requires a string argument inside quotes to display the message.
Complete the code to change the text of a paragraph with id 'text' when the button is clicked.
document.getElementById('myButton').addEventListener('click', function() { document.getElementById('text').[1] = 'Text changed!'; });
textContent changes the visible text inside an element safely without HTML parsing.
Fix the error in the code to toggle a CSS class 'active' on a div with id 'box' when clicked.
document.getElementById('box').addEventListener('click', function() { this.classList.[1]('active'); });
The toggle method adds the class if missing, or removes it if present, perfect for toggling.
Fill both blanks to create a function that changes the background color of the body to blue when called.
function changeBackground() { document.body.style.[1] = [2]; }In JavaScript, CSS properties use camelCase like backgroundColor, and color values must be strings in quotes.
Fill all three blanks to create an event listener that changes the text of a button to 'Clicked!' when it is clicked.
document.getElementById([1]).addEventListener([2], function() { this.[3] = 'Clicked!'; });
The element id is 'myButton' (string), the event is 'click' (string), and textContent changes the button's visible text.