Skip to content

Instantly share code, notes, and snippets.

@ursi
Created November 1, 2019 20:18
Show Gist options
  • Save ursi/1bf7dd550406bdebc62b854b9f1cfc24 to your computer and use it in GitHub Desktop.
Save ursi/1bf7dd550406bdebc62b854b9f1cfc24 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width'>
<style>
html {
font-size: 200%;
}
body {
font-family: monospace;
}
#key,
#guess {
display: block;
--margin: 1rem;
width: calc(100% - 2 * var(--margin));
font-family: inherit;
font-size: inherit;
margin: var(--margin);
}
</style>
</head>
<body>
<input id='guess'>
<input id='key'>
<label><input id='hide' type='checkbox'>hide</label>
<script>
const
guess = document.getElementById(`guess`),
key = document.getElementById(`key`),
hide = document.getElementById(`hide`);
guess.addEventListener(`input`, function(){
if (!key.value.startsWith(this.value)) {
guess.placeholder = key.value.slice(guess.value.length - 1);
guess.value = ``;
} else if (this.value === key.value) {
this.value = `good job`
}
});
hide.addEventListener(`change`, function(){
let visibility;
if (this.checked) {
visibility = `hidden`;
} else {
visibility = `visible`;
}
key.style.visibility = visibility
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment