cleaner tutorial match code, improved page 2 logic

This commit is contained in:
Kyle Drake 2016-04-15 15:35:01 -07:00
parent 4f0eb2b82b
commit 10789f46f4
2 changed files with 25 additions and 31 deletions

View file

@ -35,46 +35,28 @@
function checkHomework() {
var html = editor.getValue()
var match = '<html>.+</html>'
var re = new XRegExp(match, 'gis')
if(html.match(re) === null) {
notok("You're missing the HTML element tag! Your web site must begin with <html> and end with </html>.")
if(!html.tutorialMatches('<html>.+</html>')) {
notok("You're missing the HTML element tag! Your web site must begin with &lt;html&gt; and end with &lt;/html&gt;.")
return
}
/*
var match = '<html.+>.+<body></body>.+</html>'
var re = new XRegExp(match, 'gis')
if(html.match(re) === null) {
notok("You need to add some text inside the &lt;body&gt;&lt;/body&gt;.")
return
}
*/
var match = 'Hello World'
var re = new XRegExp(match, 'gis')
if(html.match(re) !== null) {
if(html.tutorialMatches('Hello World!')) {
notok("Hint: Try changing \"Hello World\" to something else.")
return
}
if(!html.tutorialMatches('<html>.+<body>.+</body>.+</html>')) {
notok('Missing the &lt;body&gt; and/or the &lt;/body&gt; tag.')
return
}
if(html.match(/<body>[\s\n]+<\/body>/) !== null) {
notok('Need to add text between the &lt;body&gt; and the &lt;/body&gt; tags.')
return
}
sessionStorage.setItem('tutorialHtml', html)
ok('Great, you did it!', '/tutorial/html/3')
/*
var match = '<html.+>.+<body>.+</body>.+</html>'
var re = new XRegExp(match, 'gis')
if(html.match(re) === null) {
notok("That's not right! Try again.")
} else {
sessionStorage.setItem('tutorialHtml', html)
ok('Great, you did it!', '/tutorial/html/3')
}
*/
}
</script>

View file

@ -80,6 +80,18 @@
<script type="text/javascript">
var infoObj = $('.error')
String.prototype.tutorialMatches = function(regex, opts) {
if(!opts)
var opts = 'gis'
var result = this.match(new XRegExp(regex, opts))
if(result == null)
return false
return true
}
function notok(msg) {
displayInfo('<i class="fa fa-exclamation-triangle"></i> ' + msg, {
background: '#93771B'