|
||||||
| Javascript Javascript Tutorials and Code |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||||
|
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 |
|
|||||
|
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 |
|
|||||
|
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 |
| Sponsored Links |
|
|
|
|||||
|
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 |
|
|||||
|
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. |
|
|||||
|
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 |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |