Last active
May 11, 2018 05:44
-
-
Save knrt10/646bcfa7df5523fefd6ecd98daa60bb0 to your computer and use it in GitHub Desktop.
See correct wrods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @function color | |
* @param {String} quote | |
* @param {String} stringTyped | |
*/ | |
function color (quote, stringTyped) { | |
let colouredString = '' | |
let wrongInput = false | |
const quoteLetters = quote.split('') | |
const typedLetters = stringTyped.split('') | |
for (let i = 0; i < typedLetters.length; i++) { | |
// if a single mistake, | |
// the rest of the coloured string will appear red | |
if (wrongInput) { | |
colouredString += chalk.bgRed(quoteLetters[i]) | |
continue | |
} | |
if (typedLetters[i] === quoteLetters[i]) { | |
wrongInput = false | |
colouredString += chalk.green(quoteLetters[i]) | |
if (quote === stringTyped) { | |
gameEnd = true | |
} | |
} else { | |
wrongInput = true | |
colouredString += chalk.bgRed(quoteLetters[i]) | |
} | |
} | |
return colouredString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment