{"id":22,"date":"2026-02-06T15:06:24","date_gmt":"2026-02-06T15:06:24","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/m_vicander\/?p=22"},"modified":"2026-02-06T15:06:24","modified_gmt":"2026-02-06T15:06:24","slug":"how-to-make-hangman-on-html-code","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/m_vicander\/2026\/02\/06\/how-to-make-hangman-on-html-code\/","title":{"rendered":"how to make hangman on html code"},"content":{"rendered":"\n<p>how to make hangman<\/p>\n\n\n\n<p>&lt;!DOCTYPE html> &lt;html lang=&#8221;en&#8221;> &lt;head> &lt;meta charset=&#8221;UTF-8&#8243;> &lt;title>Hangman Game&lt;\/title> &lt;style> body { font-family: Arial, sans-serif; background: #222; color: #f5f5f5; display: flex; flex-direction: column; align-items: center; padding-top: 40px; } h1 { margin-bottom: 10px; } #word { font-size: 2rem; letter-spacing: 8px; margin: 20px 0; } #message { margin: 10px 0; min-height: 20px; } #tries { margin: 10px 0; } #letters { margin-top: 20px; } #letters button { margin: 3px; padding: 6px 10px; border: none; border-radius: 4px; background: #444; color: #f5f5f5; cursor: pointer; } #letters button:disabled { background: #666; cursor: default; } #reset { margin-top: 20px; padding: 8px 14px; border: none; border-radius: 4px; background: #1e90ff; color: white; cursor: pointer; } &lt;\/style> &lt;\/head> &lt;body> &lt;h1>Hangman&lt;\/h1> &lt;div id=&#8221;word&#8221;>&lt;\/div> &lt;div id=&#8221;message&#8221;>&lt;\/div> &lt;div id=&#8221;tries&#8221;>&lt;\/div> &lt;div id=&#8221;letters&#8221;>&lt;\/div> &lt;button id=&#8221;reset&#8221;>New Game&lt;\/button> &lt;script> const words = [&#8220;javascript&#8221;, &#8220;hangman&#8221;, &#8220;computer&#8221;, &#8220;browser&#8221;, &#8220;coding&#8221;, &#8220;programming&#8221;, &#8220;internet&#8221;]; let secretWord = &#8220;&#8221;; let guessedLetters = []; let remainingTries = 6; const maxTries = 6; const wordDiv = document.getElementById(&#8220;word&#8221;); const messageDiv = document.getElementById(&#8220;message&#8221;); const triesDiv = document.getElementById(&#8220;tries&#8221;); const lettersDiv = document.getElementById(&#8220;letters&#8221;); const resetBtn = document.getElementById(&#8220;reset&#8221;); function pickWord() { secretWord = words[Math.floor(Math.random() * words.length)]; } function updateWordDisplay() { let display = &#8220;&#8221;; for (let char of secretWord) { if (guessedLetters.includes(char)) { display += char + &#8221; &#8220;; } else { display += &#8220;_ &#8220;; } } wordDiv.textContent = display.trim(); } function updateTriesDisplay() { triesDiv.textContent = &#8220;Tries left: &#8221; + remainingTries; } function checkGameStatus() { const allRevealed = secretWord.split(&#8220;&#8221;).every(c => guessedLetters.includes(c)); if (allRevealed) { messageDiv.textContent = &#8220;You win! The word was: &#8221; + secretWord; disableAllButtons(); } else if (remainingTries &lt;= 0) { messageDiv.textContent = &#8220;You lost! The word was: &#8221; + secretWord; disableAllButtons(); } } function disableAllButtons() { const buttons = lettersDiv.querySelectorAll(&#8220;button&#8221;); buttons.forEach(btn => btn.disabled = true); } function handleGuess(letter, button) { if (guessedLetters.includes(letter) || remainingTries &lt;= 0) return; guessedLetters.push(letter); button.disabled = true; if (!secretWord.includes(letter)) { remainingTries&#8211;; } updateWordDisplay(); updateTriesDisplay(); checkGameStatus(); } function createLetterButtons() { lettersDiv.innerHTML = &#8220;&#8221;; const alphabet = &#8220;abcdefghijklmnopqrstuvwxyz&#8221;; for (let char of alphabet) { const btn = document.createElement(&#8220;button&#8221;); btn.textContent = char; btn.addEventListener(&#8220;click&#8221;, () => handleGuess(char, btn)); lettersDiv.appendChild(btn); } } function newGame() { guessedLetters = []; remainingTries = maxTries; messageDiv.textContent = &#8220;&#8221;; pickWord(); updateWordDisplay(); updateTriesDisplay(); createLetterButtons(); } resetBtn.addEventListener(&#8220;click&#8221;, newGame); \/\/ Start first game newGame(); &lt;\/script> &lt;\/body><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>how to make hangman &lt;!DOCTYPE html> &lt;html lang=&#8221;en&#8221;> &lt;head> &lt;meta charset=&#8221;UTF-8&#8243;> &lt;title>Hangman Game&lt;\/title> &lt;style> body { font-family: Arial, sans-serif; background: #222; color: #f5f5f5; display: flex; flex-direction: column; align-items: center; padding-top: 40px; } h1 { margin-bottom: 10px; } #word { font-size: 2rem; letter-spacing: 8px; margin: 20px 0; } #message { margin: 10px 0; min-height: 20px; } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":23,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts\/22\/revisions\/23"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}