diff --git a/assets/svg b/assets/svg new file mode 100644 index 0000000..a0288d9 --- /dev/null +++ b/assets/svg @@ -0,0 +1,32 @@ +// No new file is created in this task. However, the 'wtf.js' file is modified as follows: + +// Import the 'fs' module at the top of the file +const fs = require('fs'); + +// Modify the 'generate' function +function generate() { + var type, text, part, iter = 0, // Safety mechanism + idea = randomItem( templates ), + item = regex.exec( idea ), + copy = cloneCorpus(); + + while ( item && ++iter < 1000 ) { + type = item[ 0 ]; + text = item[ 1 ]; + part = randomItem( copy[ text ], true ); + idea = idea.replace( type, part ); + regex.lastIndex = 0; + item = regex.exec( idea ); + } + + // Read the SVG file that corresponds to the class of the character + var svgIcon = fs.readFileSync(`assets/svg/${text}.svg`, 'utf8'); + + // Update output to include the SVG icon + dom.generate.text( randomItem( responses ) ); + dom.output.html('
' + idea + '.
' + svgIcon); + + // Toggle animation + setTimeout( showOutput, 0 ); + hideOutput(); +} diff --git a/scripts/wtf.js b/scripts/wtf.js index 9d3952f..a4e2046 100644 --- a/scripts/wtf.js +++ b/scripts/wtf.js @@ -218,6 +218,7 @@ var WTF = (function() { var type, text, part, iter = 0, // Safety mechanism idea = randomItem( templates ), + icon = "assets/svg/" + text + ".svg"; item = regex.exec( idea ), copy = cloneCorpus(); @@ -228,6 +229,7 @@ var WTF = (function() { part = randomItem( copy[ text ], true ); idea = idea.replace( type, part ); + idea = idea.replace("@icon", icon); regex.lastIndex = 0; item = regex.exec( idea ); @@ -236,7 +238,7 @@ var WTF = (function() { // Update output dom.generate.text( randomItem( responses ) ); - dom.output.html('' + idea + '.
'); + dom.output.html('' + idea + '.