/    Sign up×
Community /Pin to ProfileBookmark

URGENT : – Can anyone post the code for this??

I hate to post the same thing twice, but i felt like my last post got missed…

If anyone can do the code for this it would be greatly appretiated, maybe evan paid for through paypal ?

Dont worry im 37 and its not a coursework or school project, just a voluntary computer programming course ( I missed the Javascript meetings) due 2 business….

Anyways.. here’s the task…..


——————————————————————-

A prompt should be answered by player 1 to establish the word.

Then player 2 should take over and try and guess the word.

At each turn, player 2 should be prompted for an upper case character with a string which contains the number of lives left (initially 7), the letters tried so far [in order, in square brackets] and the partly guessed word e.g. 7[]=======, 6[S]=======, 6[SA]=A===A=, etc.

A suitable character (here ‘=’) is used to indicate unguessed letters.

A life is lost with each incorrect guess.

The game should finish with the message “well done” when the word is fully guessed or “bad luck – the word was ……” if the number of lives reaches 0.

There should be validation of both players input.

Players should be able to type input in upper or lower case letters but the progress of the game should be reported using upper case.

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

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Arty_EffemNov 11.2006 — 
If anyone can do the code for this it would be greatly appretiated, maybe evan paid for through paypal
[/QUOTE]
This should fit the bill. Text file attached.

[upl-file uuid=51ecef87-3432-4b13-8164-b5654031838a size=2kB]hangman.txt[/upl-file]
Copy linkTweet thisAlerts:
@Jon_Carroll1967authorNov 11.2006 — Ahhh, that seems perfect...

How would i get that to work in a java-program tho? As in (not needing the HTML stuff??
Copy linkTweet thisAlerts:
@Arty_EffemNov 11.2006 — Ahhh, that seems perfect...

How would i get that to work in a java-program tho? As in (not needing the HTML stuff??[/QUOTE]
You asked for a JavaScript solution.

JavaScript is embedded in HTML.

Java is a different language.
Copy linkTweet thisAlerts:
@Jon_Carroll1967authorNov 11.2006 — Ahhh you see this is all new to me,

I've got it working now, however as im learning all the script and functions etc...

If you or anyone for that matter can briefly describe how the whole script works and what the functions do, it will help me grasp this much easier and quicker...

The script is below....


---------------------------------------------------------------------------------
function Hangman()

{

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("Player1, please enter your word for Player 2 to guess",""))!="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("Player 2, Please 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, Life Lost") +'nn'+ lives + ' ['+guessArr.sort()+'] ' + guessField);

}

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

}

while(Hangman())

;
×

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.17,
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,
)...