/* 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"
// 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!");
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.