Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// This array holds the words we are going to choose from.
// Feel free to add new words!
var words = ['falcons', 'panthers', 'patriots', 'chargers', 'saints'];
var wordCount = document.getElementById('wordCount');
// console.log(wordCount);
function chooseWord () {
theWord = words[Math.floor(Math.random() * words.length)];
console.log(theWord);
return theWord;
}
function blanksFromAnswer ( answerWord ) {
var result = "";
for ( i in answerWord ) {
result = "_" + result;
}
return result;
}
function alterAt ( n, c, originalString ) {
return originalString.substr(0,n) + c + originalString.substr(n+1,originalString.length);
}
function guessLetter( letter, shown, answer ) {
var checkIndex = 0;
checkIndex = answer.indexOf(letter);
while ( checkIndex >= 0 ) {
shown = alterAt( checkIndex, letter, shown );
checkIndex = answer.indexOf(letter, checkIndex + 1);
}
return shown;
}
document.getElementById("WORD").innerHTML = chooseWord;
var answerWord = chooseWord();
var blanksResult = blanksFromAnswer(answerWord);
document.onkeyup = function(event) {
var userKey = event.key;
}
<!DOCTYPE html>
<html>
<head>
<title> Hangman </title>
<link rel="stylesheet" type="text/css" href="style_NFL.css">
</head>
<header>
<center>
<img src="nfl.png" width= "900px;" height="150px"; />
</center>
</header>
<body>
<div class="main_container">
<div class="container_left">
<h1 id="wordCount"></h1>
THE WORD IS <span id="WORD"></span>
<h2>A</h2>
</div>
<div class="container_right">
<h2>B</h2>
</div>
</div>
<script src="hangman.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.