Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Looking for JavaScript</title>
- <script>
- window.addEventListener("load",registerEvents,false);
- function registerEvents(e){
- document.getElementById("ask").addEventListener("click",findAnswer,false);
- }
- function findAnswer(){
- //get the user's question
- var question = document.getElementById("userQuestion").value;
- /*create a new regular expression object that will look for an exact match of the string "JavaScript"*/
- var re = new RegExp("JavaScript");
- //if "JavaScript" is found in the users question
- if(re.test(question)===true){
- //print out an answer
- document.getElementById("answer").innerHTML = "JavaScript Question? Check out coding with JavScript For Dummies by Chris Minnick and Eva Holland";
- // and yell "JavaScript" in the console
- console.log("JavaScript!");
- }
- }
- </script>
- </head>
- <body>
- <form id="userQuestion">
- <label>Enter Your Question:
- <textarea id="userQuestion"></textarea>
- </label>
- <button id="ask" type="button">Get an Answer</button>
- </form>
- <div id="answer"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement