Expression Quiz
by Tim Morgan
HTML
<h1>COMP 9633 Quiz #2</h1>
<h2>Regular Expressions</h2>
<h3>http://jsfiddle.net/jkoudys/bqRLU/</h3>
CSS
h3 { font-size:40px; }
JavaScript
/* Story Time!
* -----------
* The kids are almost ready for bed, but first they need to be read a story.
* Use your knowledge of regular expressions to find a nice book for them. Write your
* regular expressions to answer the questions below, and I'll compare my strings to
* see that they work.
*
* Make the checkStory() return true if the story should be read, and false if it shouldn't be.
* Keep this cheat-sheet open the whole time: http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/
* If you're really stumped, there's MDN: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
*/
function checkStory(story) {
// Q1. Make sure it's a faery tail. Match a story only if it starts with "Once upon a time"
//if (story.match ==
// Q2. We don't want a story that's too scary -- check if there's a dragon and return false if there is.
// Q3. No mushy stuff either -- return false if here's a "kiss" or a "hug" in this one
// Q4. We want a story for older kids - check that there are at least 10 words in this story
// Q5. Make sure it ends with "The End."
return true;
}
if (checkStory("Once upon a time, there was a scary dragon who could only be defeated by regular expressions. Nobody could stop him, and he burninated the whole countryside. The End.")) {
console.log("Let's read this book!");
}