Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

JavaScript:Tutorial, Your First Game!


  • Please log in to reply
35 replies to this topic

#13 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 25 March 2008 - 02:17 PM

You are welcome :D
  • 0

#14 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 25 March 2008 - 02:30 PM

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


<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>

  • 0

#15 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 25 March 2008 - 03:56 PM

It's a nice effect. Makes the page 'dynamic'
  • 0

#16 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 25 March 2008 - 04:24 PM

I just learned how to do that recently, it makes the page more interesting.
  • 0

#17 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 27 March 2008 - 03:39 AM

Yeah in fact.. Might come on handy sometimes.

Did you learn this from that HTML course you took?
  • 0

#18 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 27 March 2008 - 08:09 AM

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.
  • 0

#19 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 27 March 2008 - 11:09 AM

So you just learn plain HTML? Seems boring... what's HTML without JS and CSS.
  • 0

#20 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 27 March 2008 - 11:23 AM

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 :(
  • 0

#21 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 27 March 2008 - 01:13 PM

No offense, but seems like you are really wasting your time.
  • 0

#22 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 27 March 2008 - 01:16 PM

It does seem that I am wasting my time, but I need to take the course to get into the grade 12 web design course. The only useful part of it, is we learn how to use dreamweaver.
  • 0

#23 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 27 March 2008 - 02:18 PM

What will you do in the grade 12 web design?
  • 0

#24 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 27 March 2008 - 02:44 PM

The school board domain is down and all the sub domains along with it so I can't check right now.
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download