/    Sign up×
Community /Pin to ProfileBookmark

Need help with code and html?

With the below javascript for a hangman game, it currently doesnt work in a ‘Javascript tester’ (as in just runs java language) How can i convert that so its just the java and not html?


———————————————————————

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd“>
<HTML>
<HEAD>
<TITLE>Poxy Hangman</TITLE>
</HEAD>
<BODY>
Hangman…
<SCRIPT type=’text/javascript’>

function Hangman() /*2843294172747920456666656D*/
{
var quit=false, lives=7, guessed=””, guessArr=[],inp=”, inpErr=false, theWord, complete=false;

var manDiag=”n-¬n***|n***On**/|n***|n**/“;

while(typeof(inp=prompt(“Enter the word or nothing to quit”,””))!=”string” || (inpErr=(inp!=”” && /[^a-z]/i.test(inp))) )
if(inpErr)
alert(‘Letters only!’);

if(inp==””)
quit=true;
else
theWord=inp.toUpperCase();

while(!quit && !complete && lives)
{
inpErr=true;

while(inpErr && !quit)
{

do{ while( typeof(inp=prompt(“Enter one letter”,””))!=’string’ || inp==””)
;

inp=inp.toUpperCase();

if( inpErr=(guessed.indexOf(inp)>-1) )
alert(inp+’ already guessed’);
}while( !/^[a-z]$/i.test(inp) || inpErr );

}

guessed+=inp;
guessArr[guessArr.length]=inp

if( !(guessOK=theWord.indexOf(inp)>-1) )
lives–;

for(var i=0, complete=true, found, guessField=”; i<theWord.length; i++)
{
if( guessed.indexOf(theWord.charAt(i)) == -1)
{
complete=false;
found=false;
}
else
found=true;

guessField+=( found ? theWord.charAt(i) : ‘-‘ );
}

alert(inp + (guessOK ? ” Correct!”:” Wrong”) +’nn’+ lives + ‘ [‘+guessArr.sort()+’] ‘ + guessField);

}

return quit?false:confirm(“You “+(complete ? “won!”?”lost, the word was “+theWord+manDiag)) + “nnPlay again?”);

}

while(Hangman())
;


———————————————————————

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Jon_Carroll1967 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...