Exercise Set 3

Exercise 6 of 6

Change the button's background color when the buttons are clicked. Look at the last exercise.


<button id="button1">Button 1</button>
<button id="button2">Button 2</button>
<button id="button3">Button 3</button>


var button1 = document.getElementById("button1");
var button2 = document.getElementById("button2");
var button3 = document.getElementById("button3");

button1.addEventListener("click", changeColor);
button2.addEventListener("click", changeColor);
button3.addEventListener("click", changeColor);

function changeColor() {
    // your code will appear here

You must be signed in to type your code.

Show your answers to the instructor before moving on.

Last exercise Next topic First exercise