HANGMAN GAME IN JAVASCRIPT
<html>
<script>
alert("Note: This ia a Game where You will guess words by using input as letters you shoud give input based on blankspaces && your guessing is limited to 15");
var words= ["javascript","monkey","amazing","pancake","album",
"atlas",
"bestseller",
"booklet",
"brochure",
"codex",
"compendium",
"copy",
"dictionary",
"dissertation",
"edition",
"encyclopedia",
"essay",
"fiction",
"folio",
"handbook",
"hardcover",
"leaflet",
"lexicon",
"magazine",
"manual",
"monograph","nonfiction",
"novel",
"octavo",
"offprint",
"omnibus",
"opus",
"opuscule",
"pamphlet",
"paperback",
"periodical",
"portfolio",
"preprint",
"primer",
"publication",
"quarto",
"reader",
"reprint",
"roll",
"scroll",
"softcover",
"speller",
"text",
"textbook",
"thesaurus",
"tome",
"tract",
"treatise",
"vade mecum",
"volume",
"work",
"writing"];
var word= words[Math.floor(Math.random()*words.length)];
var answerArray= [];
for(var i=0;i< word.length;i++)
{
answerArray[i]= "_";
}
var remainingLetters= word.length;
var gusses=0
alert("Blank spaces will be displayed i.e, a n no.of letter word u need to guess");
while(remainingLetters>0&&gusses<15)
{
alert(answerArray.join(" "));
var guess= prompt("Guess a letter,or Click Cancel to stop playing.If ur guess is incoorect blank spaces will be displayed");
gusses++;
if(guess===null)
{
break;
}
else if(guess.length!==1)
{
alert("Please enter a single letter");
}
else
{
for(var j=0;j<word.length;j++)
{
if(word[j]===guess.toLowerCase())
{
answerArray[j] = guess.toLowerCase();
if(answerArray[j]==="_")
{
remainingLetters--;
}
}
}
}
}
alert(answerArray.join(" "));
alert("Good job! The answer was " + word);
</script>
</html>
<script>
alert("Note: This ia a Game where You will guess words by using input as letters you shoud give input based on blankspaces && your guessing is limited to 15");
var words= ["javascript","monkey","amazing","pancake","album",
"atlas",
"bestseller",
"booklet",
"brochure",
"codex",
"compendium",
"copy",
"dictionary",
"dissertation",
"edition",
"encyclopedia",
"essay",
"fiction",
"folio",
"handbook",
"hardcover",
"leaflet",
"lexicon",
"magazine",
"manual",
"monograph","nonfiction",
"novel",
"octavo",
"offprint",
"omnibus",
"opus",
"opuscule",
"pamphlet",
"paperback",
"periodical",
"portfolio",
"preprint",
"primer",
"publication",
"quarto",
"reader",
"reprint",
"roll",
"scroll",
"softcover",
"speller",
"text",
"textbook",
"thesaurus",
"tome",
"tract",
"treatise",
"vade mecum",
"volume",
"work",
"writing"];
var word= words[Math.floor(Math.random()*words.length)];
var answerArray= [];
for(var i=0;i< word.length;i++)
{
answerArray[i]= "_";
}
var remainingLetters= word.length;
var gusses=0
alert("Blank spaces will be displayed i.e, a n no.of letter word u need to guess");
while(remainingLetters>0&&gusses<15)
{
alert(answerArray.join(" "));
var guess= prompt("Guess a letter,or Click Cancel to stop playing.If ur guess is incoorect blank spaces will be displayed");
gusses++;
if(guess===null)
{
break;
}
else if(guess.length!==1)
{
alert("Please enter a single letter");
}
else
{
for(var j=0;j<word.length;j++)
{
if(word[j]===guess.toLowerCase())
{
answerArray[j] = guess.toLowerCase();
if(answerArray[j]==="_")
{
remainingLetters--;
}
}
}
}
}
alert(answerArray.join(" "));
alert("Good job! The answer was " + word);
</script>
</html>
Comments
Post a Comment