Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with "game" script

Status
Not open for further replies.

doom8890

Programmer
Aug 7, 2010
2
HR
Hello all, I would like help with JavaScript. I am making "game" in style like Click Challange on facebook. Or for those who don't use facebook, it is "game" Where you click one button and for each click you get 1 point. You have 10 seconds to do it. So players compete who will get more clicks in 10 seconds.

Anyway: I made button and you get 1 point for each. But i can't set timer... I am "beginner" in JavaScript....

Here is the script:


<head>
<title>Doom's clicking mania</title>
<link rel="stylesheet" type="text/css" href="style.css"></link>
<meta http-equiv="generator" content="CoffeeCup HTML Editor ( />
<meta name="created" content="sub, 07 kol 2010 22:04:54 GMT" />
<meta http-equiv="content-type" content="text/html;charset=windows-1250" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript">
/* Doom's click mania
Credits:Doom(Dino Aljeviæ) for HTML and JavaScript coding
Lolman(Sanjin Kalanj) for idea of this "game"
*/
var c=0;
function clickIt()
{
c++;
document.getElementById('score').value=c;
if(c>=100)
{
alert("You have reached 100 or above clicks before timer expired! You are Champinon!");
}
}
</script>
<title>Timer</title>
</head>
<body>
<form>
<input type="button" onClick="clickIt()" value="Click it"></input>
<input type="text" id="score" size="20"></input>
</form>
Doom's clicking mania 1.0
<br />Credits:
<br />Doom(Dino Aljeviæ) for HTML and JavaScript coding
<br />Lolman(Sanjin Kalanj) for idea
</body>
</html>


If you can help me make script that set timer to 10 seconds and when timer finish you get something like 'alert("You reached " + c + "clicks");'
 
Look at the setTimeout() function.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Yes i already knew for setTimeout() function but i didn't use it right so thats why i didn't get good results. I read web page on your link so i got better understanding of setTimeout(). Thanks

I made it to work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top