Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!Doctype html>
- <html lang="en">
- <head>
- <style>
- ul {
- display: inline;
- list-style-type: none;
- }
- .boxes {
- font-size:1.6em;
- text-align:center;
- width: 10px;
- border-bottom: 3px solid black;
- margin: 5px;
- padding: 10px;
- display: inline;
- }
- .hidden {
- visibility: hidden;
- }
- .visible {
- visibility: visible;
- }
- </style>
- </head>
- <body>
- <script>
- var possibleWord = ["COW", "BETTER", "HARDER", "JUSTIFY", "CONDEMN",
- "CONTROL", "HELLO", "UNDERSTAND", "LIFE", "INSIGHT","DATE",
- "RIGHTEOUSNESS"];
- var hangmanWord = possibleWord[Math.floor(Math.random() *
- possibleWord.length)];
- var underlineHelp;
- var space;
- var guess;
- var guesses = [];
- var placement;
- var underscores = [];
- var character = [];
- var textNodes = [];
- window.onload = function () {
- placement = document.getElementById('hold');
- underlineHelp = document.createElement('ul');
- placement.appendChild(underlineHelp);
- for (i = 0; i < hangmanWord.length; i++) {
- underscores = document.createElement('li');
- underscores.setAttribute('class', 'boxes');
- guesses.push(underscores);
- underlineHelp.appendChild(underscores);
- character = document.createElement('span');
- character.appendChild(document.createTextNode(hangmanWord[i]));
- character.classList.add('hidden');
- underscores.appendChild(character);
- }
- for(x=1;x<=26;x++){
- document.getElementById("test").innerHTML = hangmanWord;
- var btn = document.createElement("BUTTON");
- var myP = document.createElement("br");
- var letter = String.fromCharCode(x+64);
- var t = document.createTextNode(letter);
- btn.appendChild(t);
- btn.id = letter;
- btn.addEventListener("click", checkLetter);
- document.body.appendChild(btn);
- //add a line break 'myP' after 3 buttons
- if (x%10==0) {
- document.body.appendChild(myP);
- }
- }
- }
- function checkLetter(){
- //this refers to the object that called this function
- document.getElementById("p1").innerHTML += this.id;
- for (i = 0; i < hangmanWord.length; i++) {
- guess = hangmanWord[i];
- if (this.id == guess) {
- character[i] = hangmanWord[i];
- character.appendChild(document.createTextNode(hangmanWord[i]));
- character.classList.add('visible');
- }
- }
- }
- </script>
- </head>
- <body>
- <p>Click the button to make a BUTTON element with text.</p>
- <div id = "contents">
- <div id = "hold"></div>
- </div>
- <p id ="p1"> Letters picked: </p>
- <div id= "picBox"></div>
- <div id = "test"></div>
- </div>
- </body>
Add Comment
Please, Sign In to add comment