Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions assets/svg
Original file line number Diff line number Diff line change
@@ -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('<p>' + idea + '.</p>' + svgIcon);

// Toggle animation
setTimeout( showOutput, 0 );
hideOutput();
}
4 changes: 3 additions & 1 deletion scripts/wtf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 );
Expand All @@ -236,7 +238,7 @@ var WTF = (function() {
// Update output

dom.generate.text( randomItem( responses ) );
dom.output.html('<p>' + idea + '.</p>');
dom.output.html('<p>' + idea + '. <img src="' + icon + '" alt="' + text + ' icon"></p>');

// Toggle animation

Expand Down