Lost Password?

  #11 (permalink)  
Old 03-25-2008, 07:11 AM
TcM's Avatar   
TcM TcM is offline
Code Slinger.. FTW!
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 6,443
Rep Power: 60
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default Re: JavaScript:Tutorial, Your First Game!

Well I don't know why, but your code does not show any dialog, but it's pretty simple, your value of count is remaining 1 because. you are declaring it as 0 within the function, so whenever you press the button it declares it 0 and then increases it by 1, then again you press the button and it declares it as 0 and increases it by one, so just declare out of the function it's self, below the num variable.

I made this code for you hope it helps:

Code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var num = Math.floor(Math.random() * 101);
var count = 0;
function guessnum()
		{
			var guess = document.forms['form1'].num.value;
			if (guess == num)
				{
					count+=1;
					alert("Great you Guessed! took you" + count);
				}
			if (guess < num)
				{
					count+=1;
					alert("No your number is too low! Count " + count);
				}
			if (guess > num)
				{
					count+=1;
					alert("No your number is too  high Count " + 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>
__________________
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
  #12 (permalink)  
Old 03-25-2008, 03:24 PM
chili5's Avatar   
chili5 chili5 is online now
Guru
 
Join Date: Mar 2008
Location: Canada
Age: 15
Posts: 1,821
Rep Power: 16
chili5 is a jewel in the roughchili5 is a jewel in the roughchili5 is a jewel in the rough
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!

Thanks that seems to be rather silly, but now that you point out my error it makes sense, I'm not sure why it's not displaying dialog it worked for me this morning.

And I got it to show on the page how many guesses the user took.

Thanks again
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 03-25-2008, 05:17 PM
TcM's Avatar   
TcM TcM is offline
Code Slinger.. FTW!
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 6,443
Rep Power: 60
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default Re: JavaScript:Tutorial, Your First Game!

You are welcome
__________________
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
  #14 (permalink)  
Old 03-25-2008, 05:30 PM
chili5's Avatar   
chili5 chili5 is online now
Guru
 
Join Date: Mar 2008
Location: Canada
Age: 15
Posts: 1,821
Rep Power: 16
chili5 is a jewel in the roughchili5 is a jewel in the roughchili5 is a jewel in the rough
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!

here is my finished code, it uses the div id="counter" to show how many guesses up to date so far.

HTML Code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var num = Math.floor(Math.random() * 101);
var count = 0;
function guessnum()
		{
			var guess = document.forms['form1'].num.value;
			if (guess == num)
				{
					count+=1;
					alert("Great you Guessed! took you" + count);
					document.getElementById('counter').innerHTML = "Congrats you won, it took you " + count + " guesses to win.";
				}
			if (guess < num)
				{
					count+=1;
					alert("No your number is too low! Count " + count);
document.getElementById('counter').innerHTML = "No your number is too low " + count + " guesses so far.";
				}
			if (guess > num)
				{
					count+=1;
					alert("No your number is too  high Count " + count);
document.getElementById('counter').innerHTML = "No your number is too high " + count + " guesses so far.";
				}
		}
</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>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 03-25-2008, 06:56 PM
TcM's Avatar   
TcM TcM is offline
Code Slinger.. FTW!
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 6,443
Rep Power: 60
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default Re: JavaScript:Tutorial, Your First Game!

It's a nice effect. Makes the page 'dynamic'
__________________
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
  #16 (permalink)  
Old 03-25-2008, 07:24 PM
chili5's Avatar   
chili5 chili5 is online now
Guru
 
Join Date: Mar 2008
Location: Canada
Age: 15
Posts: 1,821
Rep Power: 16
chili5 is a jewel in the roughchili5 is a jewel in the roughchili5 is a jewel in the rough
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!

I just learned how to do that recently, it makes the page more interesting.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 03-27-2008, 06:39 AM
TcM's Avatar   
TcM TcM is offline
Code Slinger.. FTW!
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 6,443
Rep Power: 60
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default Re: JavaScript:Tutorial, Your First Game!

Yeah in fact.. Might come on handy sometimes.

Did you learn this from that HTML course you took?
__________________
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
  #18 (permalink)  
Old 03-27-2008, 11:09 AM
chili5's Avatar   
chili5 chili5 is online now
Guru
 
Join Date: Mar 2008
Location: Canada
Age: 15
Posts: 1,821
Rep Power: 16
chili5 is a jewel in the roughchili5 is a jewel in the roughchili5 is a jewel in the rough
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!

No I didn't the only HTML course that I've done is a basic course on like basic HTML. I learned how to do this from reading books and online tutorials.

Believe it or not, but my high school only has two courses in HTML and they all don't even touch javascript or anything like that.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 03-27-2008, 02:09 PM
TcM's Avatar   
TcM TcM is offline
Code Slinger.. FTW!
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 6,443
Rep Power: 60
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default Re: JavaScript:Tutorial, Your First Game!

So you just learn plain HTML? Seems boring... what's HTML without JS and CSS.
__________________
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
  #20 (permalink)  
Old 03-27-2008, 02:23 PM
chili5's Avatar   
chili5 chili5 is online now
Guru
 
Join Date: Mar 2008
Location: Canada
Age: 15
Posts: 1,821
Rep Power: 16
chili5 is a jewel in the roughchili5 is a jewel in the roughchili5 is a jewel in the rough
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!

Yep that's all we do is HTML, it would be more interesting with CSS and JS. I know some about XHTML and most of the rules with it, but she's making me go back to using old HTML
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 07:38 PM.

Contest Stats

Xav ........ 164.00000
dargueta ........ 128.00000
John ........ 127.00000
gaylo565 ........ 18.00000
XaNaX ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

Ads