Lost Password?

  #1 (permalink)  
Old 12-05-2006, 03:05 PM
TcM's Avatar   
TcM TcM is offline
Terminator - I'll be back
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 5,718
Rep Power: 47
TcM is a jewel in the roughTcM is a jewel in the roughTcM is a jewel in the rough
Default JavaScript:Tutorial, Your First Game!

Introduction:-
Here I will show you how to make a simple 'Guess The Number' game. It will do fine as your first game!

Solution:-
This goes in the <head>:-
Code:
<SCRIPT LANGUAGE="JavaScript">
var num = Math.floor(Math.random() * 101);
function guessnum(){
var guess = document.forms['form1'].num.value;
if (guess == num)
{
alert("Great you Guessed! How did you know that?");
}
if (guess < num)
{
alert("No your number is too low!");
}
if (guess > num)
{
alert("No your number is too  high");
}
}
</SCRIPT>
And this in the <body>
Code:
<form name="form1">
Enter a number <input type="text" size=5 maxlength=3
name="num"> <input type="button" onClick="guessnum();"
value="Enter">
</form>
Explanation:-
Code:
var num = Math.floor(Math.random() * 101);
This is a Mathematical Function Math.Random() is to choose a random number *101 means up to 100 so the numbers will be from 0 to 100 and Math.floor is so to eliminate any decimal points

A Preview:-


Conclusion:-
As Always Feedback is welcome and the full source is attached!!
Attached Files To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall


Business Directory | Technology Blog | Windows Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 11-17-2007, 06:27 AM
ahmed_14_1 ahmed_14_1 is offline
Newbie
 
Join Date: Nov 2007
Posts: 1
Rep Power: 0
ahmed_14_1 is on a distinguished road
Default

thanks man for this code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-18-2008, 06:42 AM
$RaMRoM$ $RaMRoM$ is offline
Newbie
 
Join Date: Oct 2007
Posts: 6
Rep Power: 0
$RaMRoM$ is on a distinguished road
Default

wow! javaScript is amazing! thanks a lot!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-12-2008, 01:45 PM
chili5's Avatar   
chili5 chili5 is offline
Speaks fluent binary
 
Join Date: Mar 2008
Location: Canada
Age: 15
Posts: 1,250
Rep Power: 10
chili5 will become famous soon enough
Send a message via ICQ to chili5 Send a message via AIM to chili5 Send a message via MSN to chili5 Send a message via Yahoo to chili5
Thumbs up Re: JavaScript:Tutorial, Your First Game!

I don't see anything in the code section.

I've seen this before its really cool though and very easy to change the range for the random number.

----------------
Now playing: Disturbed - I'm Alive
via FoxyTunes
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-22-2008, 10:37 AM
TcM's Avatar   
TcM TcM is offline
Terminator - I'll be back
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 5,718
Rep Power: 47
TcM is a jewel in the roughTcM is a jewel in the roughTcM is a jewel in the rough
Default Re: JavaScript:Tutorial, Your First Game!

What code section? You mean the code tags are empty??

Well they are not empty for me :S
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall


Business Directory | Technology Blog | Windows Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 03-22-2008, 12:05 PM
chili5's Avatar   
chili5 chili5 is offline
Speaks fluent binary
 
Join Date: Mar 2008
Location: Canada
Age: 15
Posts: 1,250
Rep Power: 10
chili5 will become famous soon enough
Send a message via ICQ to chili5 Send a message via AIM to chili5 Send a message via MSN to chili5 Send a message via Yahoo to chili5
Default Re: JavaScript:Tutorial, Your First Game!

Last time I was here, the code tags were empty.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-22-2008, 05:03 PM
TcM's Avatar   
TcM TcM is offline
Terminator - I'll be back
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 5,718
Rep Power: 47
TcM is a jewel in the roughTcM is a jewel in the roughTcM is a jewel in the rough
Default Re: JavaScript:Tutorial, Your First Game!

Maybe because you did not have enough posts to view the code in the threads?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall


Business Directory | Technology Blog | Windows Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-22-2008, 05:22 PM
chili5's Avatar   
chili5 chili5 is offline
Speaks fluent binary
 
Join Date: Mar 2008
Location: Canada
Age: 15
Posts: 1,250
Rep Power: 10
chili5 will become famous soon enough
Send a message via ICQ to chili5 Send a message via AIM to chili5 Send a message via MSN to chili5 Send a message via Yahoo to chili5
Default Re: JavaScript:Tutorial, Your First Game!

Wait you have to have a certain number of posts to see code?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-23-2008, 04:29 AM
TcM's Avatar   
TcM TcM is offline
Terminator - I'll be back
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 5,718
Rep Power: 47
TcM is a jewel in the roughTcM is a jewel in the roughTcM is a jewel in the rough
Default Re: JavaScript:Tutorial, Your First Game!

Well I don't know... but the code was always there... thats why I asked you... can't understand why you did not see it.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall


Business Directory | Technology Blog | Windows Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 03-24-2008, 11:10 AM
chili5's Avatar   
chili5 chili5 is offline
Speaks fluent binary
 
Join Date: Mar 2008
Location: Canada
Age: 15
Posts: 1,250
Rep Power: 10
chili5 will become famous soon enough
Send a message via ICQ to chili5 Send a message via AIM to chili5 Send a message via MSN to chili5 Send a message via Yahoo to chili5
Default Re: JavaScript:Tutorial, Your First Game!

Well it's working for me now. I was trying to add something to this, to keep the number of guesses. Here's my code, i think i got it working where it shows the number of guesses.

HTML Code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var num = Math.floor(Math.random() * 101);
function guessnum(){
var guess = document.forms['form1'].num.value;
var count = 0;
if (guess == num)
{
alert("Great you Guessed! How did you know that?");
count += 1
document.getElementById('counter').innerHTML = "Congratulations! you guessed the number! 

It took you " + count + " guesses to win.";
}
if (guess < num)
{
alert("No your number is too low!");
count += 1;
document.getElementById('counter').innerHTML = "Number of guesses: " + count;

}
if (guess > num)
{
alert("No your number is too  high");
count += 1;
document.getElementById('counter').innerHTML = "Number of guesses: " + count;

}
}
</SCRIPT>
<title>Guess the Number</title>
</head>
<body>
<form name="form1">
Enter a number <input type="text" size=5 maxlength=3
name="num"> <input type="button" onClick="guessnum();"
value="Enter">
</form>
<div id="counter">

</div>
</body>
</html>
actually the counter doesn't really work, it only gets to 1 guesses and doesn't work, could someone help me fix this help?

Last edited by chili5; 03-24-2008 at 11:16 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a card game (multiplaye online with AI).. what do I program this in? anothersoldier General Programming 1 07-19-2007 06:46 AM
Paying for Links Chan Marketing 26 05-02-2007 08:37 PM
XBox 360 XNA Game Programming Jordan C# Programming 14 09-29-2006 05:10 PM


All times are GMT -5. The time now is 11:29 PM.

Contest Stats

dargueta ........ 93.00000
John ........ 87.50000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads