Skip to content

Instantly share code, notes, and snippets.

@BeastOfADad
Created July 28, 2018 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BeastOfADad/ccf4d3cc87d6f8c9a8a71ed1a622e8ff to your computer and use it in GitHub Desktop.
Save BeastOfADad/ccf4d3cc87d6f8c9a8a71ed1a622e8ff to your computer and use it in GitHub Desktop.
JavaScript for Dummies ex 14-1 help
<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