Gardening | Loans | Secured Loans | Credit Card | UK Lottery
Javascript Challenge! [Archive] - ZGeek

PDA

View Full Version : Javascript Challenge!


FatherShark
05-11-2005, 11:41 AM
Who would like to win a 6-pack of their favourite beer (up to the value of $15).

The first person to submit working code which meets the following specifications can have a quarter of a slab on me.....

Produce a small game (game.html), which uses a counter to count every tenth of a second and the user has to try to guess when 5 seconds has elapsed before pressing the stop button.



The user gets a message saying they have won if they press stop after exactly 5 seconds; otherwise a message saying how many seconds had elapsed – with the message saying “well done – the time was ??? seconds” if they are within 0.5 seconds, otherwise “bad luck – the time was ??? seconds”. (Display the number of seconds instead of ???) .



Text on the page should say:”Ready to play?” before the game starts and then ”Press stop when 5 seconds are up” after the game starts – the game starts when the user clicks OK on an alert box. <Hint> show the counter until you get the program working.



You will need 3 functions. One function called start() should be called in the onLoad event, and it will need to display an alert box telling the user how to begin, then start the game by setting a timer to update the elapsed time on a regular basis, and finally change the words on the screen to “Press stop when 5 seconds are up”. The second function needs to update the elapsed time counter – it can show the elapsed time on the screen while you are testing but shouldn’t show the elapsed time on the screen in your final product. The third function finish() needs to be called when the user presses the stop button. It needs to clear the interval and then tell the user whether they have won, done well (between 4.5 and 5.5 seconds), or not done so well.

TheJackal001
05-11-2005, 12:37 PM
Uni / school work im guessing. Seriously just look on the net, as much as a 6 pack would be nice there are thousands of sites on the net which would have probably exactly what you want.
One i found in about two seconds Just look here (http://javascript.internet.com/games/buzzy---the-reflex-tester.html)
If i had the time i would do it but i have an exam in about two hours.

FatherShark
05-11-2005, 02:11 PM
yup, it's the tailend of a web dev work I've needed to do, and I'm completely baffled by the whole thing (being graphically rather than markup oriented).

The offer of a sixer is still out there.

FatherShark
05-11-2005, 04:27 PM
managed to produce THIS code, but for some reason does not work.....if any of you kindly folk would like to have a look, would be muchly apprecited:

http://pastebin.com/417925

TheJackal001
05-11-2005, 07:14 PM
Try this: i fixed the interweb (http://pastebin.com/417988)
I think it had to do with the structuring of your if statments. But it works now.
IE still says errors but not sure what prob chuck it in dreamweaver or frontpage to give you a position of the problem.

Happy Camper
06-11-2005, 12:24 AM
You would need a really accurate timer for this, something I dont think javascript has. Good luck anyway