Practice your typing skills with a quote from Sherlock Holmes. Click **start** to begin!
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/typing-game-solution/script.js b/typing-game-solution/script.js
new file mode 100644
index 0000000..fd55fa7
--- /dev/null
+++ b/typing-game-solution/script.js
@@ -0,0 +1,97 @@
+// inside script.js
+// all of our quotes
+const quotes = [
+ 'When you have eliminated the impossible, whatever remains, however improbable, must be the truth.',
+ 'There is nothing more deceptive than an obvious fact.',
+ 'I ought to know by this time that when a fact appears to be opposed to a long train of deductions it invariably proves to be capable of bearing some other interpretation.',
+ 'I never make exceptions. An exception disproves the rule.',
+ 'What one man can invent another can discover.',
+ 'Nothing clears up a case so much as stating it to another person.',
+ 'Education never ends, Watson. It is a series of lessons, with the greatest for the last.',
+ 'Mediocrity knows nothing higher than itself; but talent instantly recognizes genius.',
+ 'What you do in this world is a matter of no consequence. The question is what can you make people believe you have done.',
+ 'Crime is common. Logic is rare. Therefore it is upon the logic rather than upon the crime that you should dwell.',
+];
+// store the list of words and the index of the word the player is currently typing
+let words = [];
+let wordIndex = 0;
+// the starting time
+let startTime = Date.now();
+// page elements
+const quoteElement = document.getElementById('quote');
+const messageElement = document.getElementById('message');
+const typedValueElement = document.getElementById('typed-value');
+
+// at the end of script.js
+document.getElementById('start').addEventListener('click', () => {
+ // get a quote
+ typedValueElement.disabled=false;
+ const quoteIndex = Math.floor(Math.random() * quotes.length);
+ const quote = quotes[quoteIndex];
+ // Put the quote into an array of words
+ words = quote.split(' ');
+ // reset the word index for tracking
+ wordIndex = 0;
+
+ // UI updates
+ // Create an array of span elements so we can set a class
+ const spanWords = words.map(function(word) { return `${word} `});
+ // Convert into string and set as innerHTML on quote display
+ quoteElement.innerHTML = spanWords.join('');
+ // Highlight the first word
+ quoteElement.childNodes[0].className = 'highlight';
+ // Clear any prior messages
+ messageElement.innerText = '';
+
+ // Setup the textbox
+ // Clear the textbox
+ typedValueElement.value = '';
+ // set focus
+ typedValueElement.focus();
+ // set the event handler
+
+ // Start the timer
+ startTime = new Date().getTime();
+ });
+
+ // at the end of script.js
+typedValueElement.addEventListener('input', getInput);
+
+
+
+function getInput(){
+ // Get the current word
+ const currentWord = words[wordIndex];
+ // get the current value
+ const typedValue = typedValueElement.value;
+
+ if (typedValue === currentWord && wordIndex === words.length - 1) {
+ // end of sentence
+ // Display success
+ const elapsedTime = new Date().getTime() - startTime;
+ const message = `CONGRATULATIONS! You finished in ${elapsedTime / 1000} seconds.`;
+ messageElement.innerText = message;
+ typedValueElement.removeEventListener('input',getInput);
+ typedValueElement.disabled=true;
+ } else if (typedValue.endsWith(' ') && typedValue.trim() === currentWord) {
+ // end of word
+ // clear the typedValueElement for the new word
+ typedValueElement.value = '';
+ // move to the next word
+ wordIndex++;
+ // reset the class name for all elements in quote
+ for (const wordElement of quoteElement.childNodes) {
+ wordElement.className = '';
+ }
+ // highlight the new word
+ quoteElement.childNodes[wordIndex].className = 'highlight';
+ } else if (currentWord.startsWith(typedValue)) {
+ // currently correct
+ // highlight the next word
+ typedValueElement.className='';
+ typedValueElement.disabled=false;
+ } else {
+ // error state
+ typedValueElement.className = 'error';
+ }
+}
\ No newline at end of file
diff --git a/typing-game-solution/style.css b/typing-game-solution/style.css
new file mode 100644
index 0000000..a366906
--- /dev/null
+++ b/typing-game-solution/style.css
@@ -0,0 +1,62 @@
+.highlight {
+ background-color: rgb(7, 182, 235);
+ }
+
+.error {
+ background-color: lightcoral;
+ border: red;
+ width: 220px;
+ height: 45px;
+ font-size: 25px;
+ font-weight: bolder;
+ }
+
+body{
+ background-color: rgb(12, 2, 2);
+}
+
+h1{
+ font-family: 'Fondamento',serif;
+ font-size: 80px;
+ color: blueviolet;
+ text-align: center;
+ }
+
+p{
+ font-family: 'Fondamento',serif;
+ font-size: 40px;
+ color: yellow;
+ text-align: center;
+}
+
+input {
+ width: 220px;
+ height: 45px;
+ font-size: 25px;
+ font-weight: bolder;
+}
+
+input:disabled {
+ width: 0px;
+ height: 0px;
+ background-color: rgb(12, 2, 2);
+}
+
+input:focus{
+ outline: none;
+ border: none;
+}
+
+button{
+ height: 45px;
+ margin-left: 30px;
+ border-color: white;
+ width: 70px;
+ font-size: 20px;
+ font-weight: bolder;
+}
+
+.typing{
+ margin-top: 90px;
+ margin-left: 40%;
+}
\ No newline at end of file