The maintainer has not written a description at the source.
Repo CoderDojoSV/javascript-browser-game, read from GitHub 1 min ago. CoderDojoSV has not joined Take My Repo.
CoderDojoSV/javascript-browser-game is a public repo on GitHub by CoderDojoSV. It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it. It has 0 stars and last changed on 2015-10-19. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-18.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
You had a chance to learn a bit about JavaScript in the last session, and the material is available at http://coderdojosv.github.io/Intro-Web-Series/
We are going to use some of the concepts learned in that session, and add to your knowledge with even more tricks. We recommend you use a web-based web-page development app like Thimble by Mozilla, CodePen.io or JSBin).
In this lesson, we will make two games that run in a browser. First up is "the number guessing game". Then, we will use that code to form the start of "Hangman"
The goal for this session is for you to learn a little more JavaScript by example, and to apply your knowledge to improve the starter code and/or the behavior of the games.
By now, you should be familiar with Web Development basics enough to understand this HTML code:
<h1>Number Guessing Game</h1> Type a number between 1 and 100 (then press guess) <input id="guess" type="text"> <input type="button" value="guess" onClick="guessOne()"/> <p id="message"> </p>
The most important thing to observe from this simple HTML is that a call is made out to JavaScript when the player makes their guess. In this case, the "guessOne()" function will be called.
Challenges (optional):
html <button> tag.Caution! In prior lessons, you may have seen the use of javascript's alert and prompt. As you learn more, you will find that alerts and prompts are good to avoid. Some development environments actively disallow them. Khan Anademy is one that disallows alerts in JavaScript. Other development environments may run your JavaScript on every key press, and the alert or prompt dialog box can be very annoying.
So, from this point on, we will send any output to a web page element we prepared for our use. In this example, we are going to write everything we need to tell the player into the area with the "message" id.
Before diving into the technical details, there's one more thing. In Khan Academy's site, there is no easy way to have your html call your own javascript that is in a separate file. (This differs from Thimble and JsBin.) So, while using Khan Academy, we will go back to the approach of putting the JavaScript code right into the html page.
Let's take a look at the first few lines in our JavaScript for The Number Guessing Game
<script> var guessCount = 0; var MAX_GUESSES = 6; var randomNumber = Math.floor((Math.random() * 100) + 1); //picks a random number between 1 and 100 function guessOne(){ ...
The most important thing to observe is that we declared that we have a function called javascript guessOne(), which is the code that gets called when the guess button is clicked. We'll talk about that code in a minute. First, let's talk about variables.
Remember that code is written to tell the computer what to do AND to tell programmers how you are doing it. Using good variable names helps make your code understandable. Placing the variables in the right place helps, too.
These variables need to be kept alive between runs of the code, so they are not in the guessOne() function. This means they are global variables. You should use as few global variables as possible, and professional developers have ways of not using global variables at all.
What are the variables we declared?
Activity:
Challenges
Here is the first half of the guessOne() function
function guessOne(){ // Get a guess from the player var guess = document.getElementById("guess").value; if (guess == randomNumber){ document.getElementById("message").innerHTML= "It took you " +guessCount+ " guesses"; return; // prevents saying 'ran out' if guessed in last round } else if (guess < randomNumber){ document.getElementById("message").innerHTML= "Guess again. The number is higher than "+guess; } else { document.getElementById("message").innerHTML= "Guess again. The number is lower than "+guess; } guessCount += 1; ...
Notice that JavaScript pulls the player's guess out of the "guess" field and puts it into the variable named "guess". This variable is declared inside the guessOne function and will disappear when the guessOne function completes.
Next, notice the "control logic". There is an if, an else-if, and a final else (which you can think of as the word "otherwise" if that helps.)
Challenges:
javascript document.getElementById("guess").value to turn it into a number. (We were lucky javascript's comparison worked when comparing a string to a number.)Activity:
A QA engineer ("Quality Assurance") tests other people's code. Here's a funny tweet Be the QA enginner for someone at your table who tries to make the code more rugged.
Here's the rest of the guessOne() function
... if (guessCount >= MAX_GUESSES) { document.getElementById("message").innerHTML= "Sorry, you ran out of guesses. The number was " + randomNumber; } // Lend a hand by clearing out their last guess document.getElementById("guess").value = ""; }
You know what the first section is doing.. It's checking if the player used up the guesses. But it is not stopping the game! Hmm, maybe you should fix that!
The last line is there to be nice to the player. It clears out their guess. Otherwise, they have to backspace out their old answer. Be kind to your users!
Challenge:
Take a moment and have someone else at your table play the game that you wrote. If they find any bugs, then take a moment to fix them.
Instead of having a "guess" button, you could create a listener on the guess html text input box. That listener should be assigned to keyboard events and look as each key is pressed. If it's a number, it's good. If it's enter, it should call guessOne. Otherwise, it should reject what the player typed. Congratulations, Your game is now zombie-proof!!
The code so far creates a decent structure fo the game "Hangman". Let's revisit the HTML and put in a few more elements.
<h1>Hangman!</h1> Type a letter (then press guess) <input id="guess" type="text"> <input type="button" value="guess" onClick="guessOne()"/> <input type="button" value="quit" onClick="quit()"/> <p id="message"> </p> <p> <font size="+3"><span id="answer">puzzle loading..</span></font> </p>
The most important thing to observe is a new element called "answer". We will use this to show the player's guess as time goes on.
Challenges:
html<img id="hangman">Let's take a look at the first few lines in our JavaScript
<script> // declare three global variables // Create an array of words-- randomly choose one on init var WORDS = [ "javascript", "hangman", "coderdojo", "games" ]; // word stores the word we want the player to guess var word=""; // answerArray stores the answer board (starting with all _ and gradually filled in) var answerArray = [];
The number game calculated a random number, This game fetches a random word from the WORDS array. (ALL_UPPERCASE indicates this never changes for the life of the game.)
Activity
Challenges: new features you can add to the game
The initialization of the game is moved to a function called init. Don't forget to call it!
function init(){ // Pick a random word word = WORDS[Math.floor(Math.random() * WORDS.length)]; // Set up the answer array answerArray = []; for (var i = 0; i < word.length; i++) { answerArray[i] = "_"; } document.getElementById("answer").innerHTML= answerArray.join(" "); document.getElementById("message").innerHTML= "Type a letter then press guess, or press quit to stop playing." } init();
So, this is a lot like the number guessing game, except the player is guessing letters. So, we are comparing strings rather than numbers.
The two other big changes here are that we are manipulating the "correct answer" array as the player gets letters correct, and that we are temporarily storing a message to display to the player after we've processed everything that could happen.
Here's that code
function guessOne() { // Get a guess from the player var guess = document.getElementById("guess").value; var showThisMessage = ""; if (guess.length !== 1) { showThisMessage ="Please enter only a single letter"; } else { // Update the game with the guess var i=0; // an indexer into the array for (i = 0; i < word.length; i++) { if (word[i] === guess) { answerArray[i] = guess; showThisMessage = "YES! "+guess+" is in the answer"; } } // Update the game for remaining unknowns var remaining_letters = answerArray.length; // recount the remaining letters for (i = 0; i < answerArray.length; i++) { if (answerArray[i] !== '_') { remaining_letters -= 1; } } // if no remaining letters, hurray, you won if (remaining_letters == 0) { showThisMessage = "YES! You guessed the word"; } // (otherwise) if we have no message, wrong guess if (showThisMessage === "") { showThisMessage = "Sorry, no "+guess; } // Update the puzzle document.getElementById("answer").innerHTML = answerArray.join(" "); // Lend a hand by clearing out their last guess document.getElementById("guess").value = ""; } document.getElementById("message").innerHTML = showThisMessage; }
There are a few noteworthy tricks here.
answerArray.join(" "); will take all the members (the letters) of the answerArray and blast them into a string. If we supply join() with the space character as the parameter, it will put spaces between each letter for us. Magically, we can get what we need with little effort.The game also has a quit button. This is the code (which is also visible on the project page
function quit() { document.getElementById("message").innerHTML = "The word was "+word; for (var j = 0; j < word.length; j++) { answerArray[j] = word[j]; } // Solve the puzzle document.getElementById("answer").innerHTML = answerArray.join(" "); }
Challenges:
The challenges sections listed some of the things you can do to the code to make it better or more like the real games.
A variant to the number game is to turn it into a game like MasterMind. In addition to higher and lower, state how many digits are in the right place. (For example, if the number to guess is "555" and the player guesses 500, say 'higher, with one number in the right place')
You could go further and turn it into MasterMind. Use letters (maybe "just vowels") and look ath the players guess and say how many are present and how many are in the right place.
It's almost inconcieveable that a JavaScript lesson doesn't talk about jQuery, but we're focusing more on the JavaScript language than all features available to web developers. jQuery makes working with HTML elements much easier. You could take this code, include jQuery,
<script src="Scripts/jquery-1.7.1.min.js"></script>
and change the getElementById calls to use the jQuery selector
$("message").innerHTML = whatever
You could turn this code into a text adventure game like this and running here. (This code uses jQuery.) I think I hear a dragon to the east!
CoderDojoSV/javascript-browser-game is a public repo on GitHub by CoderDojoSV. Its maker has not written a description.
It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2015-10-19. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.