Hope in Learning To Code: Rose From Concrete’s Hangman Game

Play the classic game Hangman right in your browser!

  • Guess one letter at a time to fill in the hidden word: each correct guess reveals its position, but each miss draws another part of the ASCII figure.
  • Win by uncovering the entire word before the Hangman is fully drawn.
  • Newly coded by an advanced-beginner (me)! This project marks my first web-based app (simple though it may be).
  • Hope in Learning To Code!
/* Scope everything to #hangmanGame */ #hangmanGame { font-family: Arial, sans-serif; margin: 20px auto; /* Centers the entire container on the page */ max-width: 600px; border: 3px solid red; /* 3px red border around the container */ padding: 10px; /* Optional padding so content isn’t up against the border */ /* NEW: Make it a flex container that aligns items to the center horizontally */ display: flex; /* Use Flexbox */ flex-direction: column; /* Stack items vertically */ align-items: center; /* Center child elements horizontally */ } #hangmanGame #wordDisplay { font-size: 1.5rem; letter-spacing: 0.2rem; /* The text will remain left-aligned by default, but the element is centered as a block */ } #hangmanGame #hangmanStage { margin-top: 1rem; white-space: pre-line; /* Preserves line breaks for ASCII art */ font-family: monospace; /* So ASCII art looks aligned */ } #hangmanGame #wrongLetters { margin-top: 1rem; font-weight: bold; color: #d00; /* Dark red for visibility, adjust to taste */ } #hangmanGame #message { margin: 1rem 0; font-weight: bold; } #hangmanGame input[type=”text”] { width: 100px; font-size: 1rem; padding: 0.2rem; } #hangmanGame button { font-size: 1rem; padding: 0.3rem 0.5rem; cursor: pointer; margin-top: 0.5rem; /* Slight spacing above buttons */ } #hangmanGame #restartBtn { display: none; background-color: #007BFF; color: #fff; border: none; } #hangmanGame #restartBtn:hover { background-color: #0056b3; }
// A list of 100 single words at about 8th-grade vocabulary level const words = [ “adventure”, “ambition”, “anniversary”, “appreciate”, “bargain”, “consequence”, “curriculum”, “demonstration”, “diversity”, “encyclopedia”, “enthusiasm”, “evaluate”, “evidence”, “extracurricular”, “foreshadowing”, “formulate”, “fortitude”, “honesty”, “hypothesis”, “inference”, “inheritance”, “innovation”, “magnitude”, “maturation”, “memoir”, “metaphor”, “millennium”, “novelty”, “perception”, “perspective”, “phenomenon”, “photosynthesis”, “pollination”, “probability”, “procrastination”, “prosperity”, “reflection”, “responsibility”, “analysis”, “appendage”, “authority”, “avalanche”, “boundary”, “camouflage”, “candidate”, “category”, “celestial”, “chemistry”, “clarify”, “corrosion”, “crystalline”, “deficiency”, “deliberate”, “diminish”, “directory”, “distortion”, “ecosystem”, “electron”, “equality”, “equation”, “equitable”, “estimate”, “expository”, “friction”, “gradient”, “hemisphere”, “hydrogen”, “imbalance”, “immortal”, “invaluable”, “irrigation”, “legislation”, “library”, “machinery”, “marvelous”, “migration”, “narrative”, “objective”, “offspring”, “ominous”, “parallel”, “particle”, “persistent”, “physical”, “polygon”, “predator”, “prejudice”, “primitive”, “radiation”, “revision”, “rigorous”, “rotation”, “sanctuary”, “sediment”, “sequence”, “sociology”, “solitary”, “triumphant”, “variable”, “velocity” ]; // ASCII stages of Hangman const hangmanStages = [ “”, “________”, “| |”, “| 0”, “| /|\\”, “| / \\”, “|” ]; let secretWord = “”; let scoreBoard = []; let stage = 0; let gameOver = false; let wrongGuesses = []; // Track wrong letters const wordDisplay = document.getElementById(“wordDisplay”); const hangmanStage = document.getElementById(“hangmanStage”); const wrongLettersDiv = document.getElementById(“wrongLetters”); const message = document.getElementById(“message”); const guessInput = document.getElementById(“guessInput”); const guessBtn = document.getElementById(“guessBtn”); const restartBtn = document.getElementById(“restartBtn”); // —————————– // Initialization / Start Game // —————————– function initGame() { stage = 0; gameOver = false; message.textContent = “”; hangmanStage.textContent = “”; restartBtn.style.display = “none”; wrongGuesses = []; wrongLettersDiv.textContent = “”; secretWord = words[Math.floor(Math.random() * words.length)]; scoreBoard = Array(secretWord.length).fill(“_”); wordDisplay.textContent = scoreBoard.join(” “); } // —————————– // Handle a Guess // —————————– function makeGuess() { if (gameOver) return; const guess = guessInput.value.toLowerCase(); guessInput.value = “”; // clear input if (!guess.match(/^[a-z]$/)) { message.textContent = “Please enter a single letter (a-z).”; return; } if (secretWord.includes(guess)) { for (let i = 0; i = hangmanStages.length – 1) { message.textContent = `You lose! The word was “${secretWord}”.`; endGame(); } } // —————————– // Update the ASCII Hangman // —————————– function updateHangmanStage(currentStage) { const partialStages = hangmanStages.slice(0, currentStage + 1); hangmanStage.textContent = partialStages.join(“\n”); } // —————————– // End the Game // —————————– function endGame() { gameOver = true; restartBtn.style.display = “inline-block”; } // —————————– // Restart Button Listener // —————————– function restartGame() { initGame(); } // —————————– // Event Listeners // —————————– guessBtn.addEventListener(“click”, makeGuess); restartBtn.addEventListener(“click”, restartGame); guessInput.addEventListener(“keyup”, function(event) { if (event.key === “Enter”) { makeGuess(); } }); initGame();

My Advanced-Beginner Coding Journey

I want to be completely transparent about where I am in my coding journey. By all accounts, I’m still an advanced-beginner—definitely less than intermediate. It’s easy to forget just how big the gap is between simple games (like my Hangman, which is only a couple hundred lines long) and the highly polished, potentially billion-lined apps everyone uses every day, such as rideshares or food delivery.

Nevertheless, for me, this little project isn’t about matching those apps in complexity. Instead, it’s about finding hope in learning something new.

A Rose Growing from Concrete

I once wrote about Tupac’s concept of a rose growing from concrete on my Tattered Rose blog. This imagery resonated deeply: a rose pushing past tough surroundings to bloom, revealing that beauty and growth can flourish in the unlikeliest places. My own life has reflected that experience.

Just four years ago, I was homeless, and statistically, the future seemed bleak. Many believed my chances of stopping my habits—let alone doing something meaningful—were almost zero. As a result, hopelessness felt like a solid barrier between me and a better life.

Rediscovering Possibility Through Learning to Code

Yet here I am, still learning and still growing. Picking up coding helped me unlock a new sense of possibility. For example, re-learning that I could tackle the fundamentals—things like loops, conditionals, and comparing guessed characters to a secret word—triggered real excitement. Some mornings, I even catch myself waking up at 6 a.m. with my first thought being whichever function I struggled with the previous night.

Consequently, this small sign of progress continues to fuel me in ways I never expected. It reminds me that, just like the rose thriving in tough conditions, we can rise above our circumstances too.


Presenting My Hangman Game

Eventually, I pieced together this Hangman game you see above. It’s quite basic—definitely not the best version you’ll ever play. However, it stands as a tangible reminder of the hope I discovered while learning a new skill. Maybe you’ll even enjoy testing your own luck against its rudimentary algorithm!

Above all, I hope this simple creation proves that, like a rose growing from concrete, meaningful progress can blossom in even the toughest circumstances.


Footnote Citations

1. “The Rose That Grew from Concrete” by Tupac Shakur – A well-known poem about hope and perseverance in difficult environments.

2. Learning to Code at Any Age (freeCodeCamp) – Resource showing that programming can be learned and mastered at different stages of life.

2 responses to “Hope in Learning To Code: Rose From Concrete’s Hangman Game”

Leave a Reply