HTML
<img src="dog.png" id="dog"> <p id="messageParagraph"></p>
JavaScript
let dog = document.getElementById(`dog`) let messageParagraph = document.getElementById(`messageParagraph`) let clicks = 0 dog.addEventListener(`click`, clickDog) function clickDog() { clicks + 1 if (clicks == 10) { messageParagraph.innerHTML = `woof woof` } }
Reason
HTML
<img src="dog.png" id="dog"> <p id="messageParagraph"></p>
JavaScript
let dog = document.getElementById(`dog`) let messageParagraph = document.getElementById(`messageParagraph`) let clicks = 0 dog.addEventListener(`click`, clickDog) function clickDog() { clicks = +1 if (clicks == 10) { messageParagraph.innerHTML = `woof woof` } }
Reason
HTML
<img src="dog.png" id="dog"> <p id="messageParagraph"></p>
JavaScript
let dog = document.getElementById(`dog`) let messageParagraph = document.getElementById(`messageParagraph`) dog.addEventListener(`click`, clickDog) function clickDog() { clicks = clicks + 1 if (clicks == 10) { messageParagraph.innerHTML = `woof woof` } }
Reason
HTML
<button id="switchButton">Flip switch</button> <p id="messageParagraph"></p>
JavaScript
let switchButton = document.getElementById(`switchButton`) let messageParagraph = document.getElementById(`messageParagraph`) let lightOn = false switchButton.addEventListener(`click`, flipSwitch) function flipSwitch() { if (lightOn == false) { messageParagraph.innerHTML = `The light is now on.` } else { messageParagraph.innerHTML = `The light is now off.` lightOn = false } }
Reason
HTML
<button id="switchButton">Flip switch</button> <p id="messageParagraph"></p>
JavaScript
let switchButton = document.getElementById(`switchButton`) let messageParagraph = document.getElementById(`messageParagraph`) let lightOn = false switchButton.addEventListener(`click`, flipSwitch) function flipSwitch() { if (lightOn = false) { messageParagraph.innerHTML = `The light is now on.` lightOn = true } else { messageParagraph.innerHTML = `The light is now off.` lightOn = false } }
Reason