JavaScript JavaScript and the DOM Getting a Handle on the DOM Selecting by Id

Ali Sh
Ali Sh
2,026 Points

How can i solve this quiz?

There is a variable named button in app.js. Set its value to contain a reference to the button element in index.html with the ID of sayPhrase.

js/app.js
let button = document.getElementById('sayPhase');
let input;

button.addEventListener('click', () => {
  alert(input.value);
});
index.html
<!DOCTYPE html>
<html>
  <head>
    <title>Phrase Sayer</title>
  </head>
  <body>
    <p><input type="text" id="phraseText"></p>
    <p><button id="sayPhrase">Say Phrase</button></p>
    <script src="js/app.js"></script>
  </body>
</html>

2 Answers

Double check the id you are using to make sure its correct.

slurpee
slurpee
6,694 Points

"sayPhrase" is spelled incorrectly.