Created
July 28, 2018 05:52
-
-
Save BeastOfADad/ccf4d3cc87d6f8c9a8a71ed1a622e8ff to your computer and use it in GitHub Desktop.
JavaScript for Dummies ex 14-1 help
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment