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

logan gomez7
PRO
logan gomez7
Front End Web Development Techdegree Student 7,669 Points

Next, select the input element with the ID phraseText and assign it to the input variable.

unclear what question is asking am I adding the phraseText id to the index.html then selecting it In js/app.js? help would be nice

js/app.js
let button= document.getElementById('sayPhrase'); 
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

Martin Jones
Martin Jones
Front End Web Development Techdegree Graduate 41,143 Points

You have answered the first part of the question correctly when you assigned the element with the 'sayPhrase' ID to the button variable.

You just need to do the exact same thing for the input variable.

let input = document.getElementById('phraseText');