/* --------------------------------------------------
If you change the pre-written variables and functions your game will break.
--------------------------------------------------- */
var word = ""; //This variable should hold the word or phrase to be guessed.
var displayWord = ""; //This variable should hold the text that you want to be printed (with blanks appropriately).
var guesses = []; //This variable should hold all of the letters that have been guessed.
var wrongCount = 0; //This variable should hold the value for how many wrong guesses have been submitted.
var hangmanImage = false; //change this to false if you want a non-hangman graphic displayed
function main(){
//use pick word function
word = pickWord();
// displayWord = word;
}
//Your other functions should go below here.
function pickWord() {
var possibleWords = ["Birdman","Betty Blue", "Amelie", "Princess Bride", "Duck Season", "Beauty and the Beast", "Up", "Finding Forester", "Clueless", "My Best Friends wedding"];
var randomN = Math.floor(Math.random() * 10);
var movie = "";
/* print("hello " + randomN) */
for(var i = 0; i< possibleWords.length; i++) {
if(randomN == i) {
movie = possibleWords[i].toLowerCase();
}
}
/* print(movie) */
formatDisplayWord();
return(movie.toLowerCase());
}
function formatDisplayWord() {
displayWord = "";
var ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
var alpha = "abcdefghijklmnopqrstuvwxyz";
var winCheck = false;
var loseCheck = false;
for(var i = 0; i < word.length; i++) {
var letter = word.charAt(i);
if(ALPHA.includes(letter) == true) {
//push guessed letter into the displayWord.
displayWord += letter;
winCheck = true;
} else {
displayWord += "_";
loseCheck = true;
}
}
if(winCheck == true) {
win();
}
if(loseCheck == true) {
lose();
}
}
function win() {
if(!displayWord.includes("_")) {
alert("YOU WON!");
}
}
function lose() {
if(wrongCount >= 7) {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.