JSFiddle - React, Tailwind, and code Playground
by Karl Hui
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) {
if(story.match(/Once upon a time/)){
if(story.match(/dragon/)){
return false;
}//Q2 closing bracket
else{ //Q2 else statement
if(story.match(/kiss/)||story.match(/hug/)){
return false;
}//Q3 closing bracket
else{ //Q3 else statement
if(story.length > 10){
if(story.match(/The end/)){
return true;
}//Q5 closing bracket
else{//Q5 else statement
return false;
}//Q5 else close bracket
}//Q4 closing bracket
else{ //Q4 else statement
return false;
}//Q4 else close bracket
} //Q3 else close bracket
} //Q2 else close bracket
}//Q1 closing bracket
else{ //Q1 else statement
return false;
} //Q1 else close bracket
}//function close bracket
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!");
}
else{
console.log("Find another book!");
}