Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a file with a possible word implementation example #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
Binary file modified sounds/a.wav
Binary file not shown.
Binary file modified sounds/b.wav
Binary file not shown.
Binary file modified sounds/c.wav
Binary file not shown.
Binary file modified sounds/d.wav
Binary file not shown.
Binary file modified sounds/e.wav
Binary file not shown.
Binary file modified sounds/f.wav
Binary file not shown.
Binary file modified sounds/g.wav
Binary file not shown.
Binary file modified sounds/h.wav
Binary file not shown.
Binary file modified sounds/i.wav
Binary file not shown.
Binary file modified sounds/j.wav
Binary file not shown.
Binary file modified sounds/k.wav
Binary file not shown.
Binary file modified sounds/l.wav
Binary file not shown.
Binary file modified sounds/m.wav
Binary file not shown.
Binary file modified sounds/n.wav
Binary file not shown.
Binary file modified sounds/o.wav
Binary file not shown.
Binary file modified sounds/p.wav
Binary file not shown.
Binary file modified sounds/q.wav
Binary file not shown.
Binary file modified sounds/r.wav
Binary file not shown.
Binary file modified sounds/s.wav
Binary file not shown.
Binary file modified sounds/t.wav
Binary file not shown.
Binary file modified sounds/u.wav
Binary file not shown.
Binary file modified sounds/v.wav
Binary file not shown.
Binary file modified sounds/w.wav
Binary file not shown.
Binary file modified sounds/x.wav
Binary file not shown.
Binary file modified sounds/y.wav
Binary file not shown.
Binary file modified sounds/z.wav
Binary file not shown.
77 changes: 77 additions & 0 deletions word-checker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<html>

<body>
<div>
<span id="w1-l1-a">a</span><span id="w1-l2-d">d</span><span
id="w1-l3-a">a</span><span id="w1-l4-m">m</span>
</div>

<div>
<span id="w2-l1-b">b</span><span id="w2-l2-i">i</span><span
id="w2-l3-l">l</span><span id="w2-l4-l">l</span>
</div>

<div>
<span id="w3-l1-j">j</span><span id="w3-l2-o">o</span><span
id="w3-l3-h">h</span><span id="w3-l4-n">n</span>
</div>
</body>

<script>
var activeWord = 0;
var words = ["adam", "bill", "john"];
var input = "";

document.body.addEventListener('keypress', function(ev) {

var typedChar = String.fromCharCode(ev.keyCode);

var currentLetter = input.length;

var currentDomLetter;
var checkWordChar;

if (activeWord === 0) {
// Check each word to see which one should become active if any
words.forEach(function(word, index) {
checkWordChar = word.substr(currentLetter, 1);
if (typedChar === checkWordChar) {
// Set the active word
activeWord = index + 1;

// Color the letter in the dom for the letter of the active word
currentDomLetter = document.getElementById(
'w' + activeWord + '-l' + (currentLetter+1) + '-' + typedChar
);
currentDomLetter.style.color = '#FF0000';

// Track input so far
input += typedChar;
}
});
} else {
// If currently typing a word then keep validating that same word
checkWordChar = words[activeWord-1].substr(currentLetter, 1);
if (typedChar === checkWordChar) {

// Color the letter in the dom for the letter of the active word
currentDomLetter = document.getElementById(
'w' + activeWord + '-l' + (currentLetter+1) + '-' + typedChar
);
currentDomLetter.style.color = '#FF0000';

// Track input so far
input += typedChar;

// Reset active word if word is completed
if (words[activeWord-1].length === input.length) {
activeWord = 0;
input = '';
}
}
}
});

</script>

</html>