Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 02-11-2007, 01:01 PM Number guess
Skilled Talker

Posts: 58
Trades: 0
A member posted this on www.progmania.dk
I thought it would be a great idea to share with you guys:

Code:
/****** Source ******/ 
     /****** irc.hackthissite.org #asshat ******/ 
/****** irc.controlthesystem.org #controlthesystem ******/ 
        /****** Number guesser ******/ 
 
<html> 
<title> Number Guesser </title> 
<body> 
<script language="javascript"> 
/** Declare Variables **/ 
var howmany; 
var endnumber; 
var wins = 0; 
var guessesleft; 
var losses = 0; 
var random; 
var guess; 
var guesses; 
var play; 
  
  
/** Alert in javascript **/  
alert("I will think of a number between one (1) and whatever number you want"); 
/** Declaring play's value as yes. I did not do this in the variables section because it would NEVER stop playing **/ 
play = "YES" 
 /** While statement means while condion x is something, keep doing something.Remember to re-check the condition so it doesnt cause an infinite loop **/ 
 while (play == "YES") { 
  endnumber = prompt("What would you like the end number to be?","Number"); 
   /** Checking to make sure that the end number is NOT 1 and it is a number (not "pizza") **/ 
   while (isNaN(endnumber) || endnumber == 1) { 
   alert("Invald number, please try again!"); 
  /** Here is where I am re-checking the condition **/ 
   endnumber = prompt("What would you like the end number to be?","Number"); 
  } 
  
 howmany = prompt("How many guesses do you want?","Number"); 
  while (isNaN(howmany)) { 
  alert("Invalid number, please try again!"); 
  howmany = prompt("How many guesses do you want?","Number"); 
} 
  
alert("I am thinking of a number between 1 and " + endnumber + " you have " + howmany + " guesses"); 
/** Math.Random gets a random number between 0 and 1. I multiply this number by the end number **/ 
random = Math.random() * endnumber; 
random = Math.ceil(random); 
  
guessesleft = howmany; 
/** While their guess does not == the number I am thinking of... They keep guessing, and then I subtract from their guesses left **/ 
while ((guess != random) && (guessesleft >= 1)) { 
  guess = prompt("I am thinking of a number between 1 and " + endnumber + " you have " + guessesleft + " guesses",""); 
  guessesleft = guessesleft - 1; 
   if(guess > random) { 
 alert("Your guess is too high"); 
 } 
   else if (guess < random) { 
 alert("Your guess is too low"); 
 } 
} 
/** If statements mean if condition is true then do this, else if means if condition 1 isnt true, do this **/ 
if(guess == random) { 
  alert("You win, " + random + " was the correct number"); 
  wins = wins + 1; 
  alert("You have " + losses + " loss(es) and " + wins + " win(s)"); 
} 
  
else if(guess != random) { 
  alert("You lose the correct number was " + random); 
  losses = losses + 1; 
  alert("You have " + losses + " loss(es) and " + wins + " win(s)"); 
} 
/** Caps.. their input otherwise they could enter "YeS" and you would get errors. **/ 
play = prompt("Do you wish to play again?","YES or NO"); 
 play = play.toUpperCase(); 
  
} 
  
if (play == "NO") { 
 alert("Thanks for playing numberguesser!"); 
} 
  
</script> 
</body> 
</html>
ProgMania is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-13-2007, 06:57 PM Re: Number guess
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
This would be a really hot computer game if it was still 1983.
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-13-2007, 07:02 PM Re: Number guess
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0


LMAO !!
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-13-2007, 10:44 PM Re: Number guess
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
That was totally uncalled for. Just because the script mentions an IRC chat room called #asshat and just because it resembles the end-of-term assignment in any high school computer class doesn't mean it's not hot.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-14-2007, 12:49 AM Re: Number guess
sukantab's Avatar
Super Talker

Posts: 113
Name: Sukanta
Trades: 0
This is a good game. I like the commnets also. It has become a habit nowadays to just write some code with no comment. The person who wrote the code made sufficient comments.
__________________

Please login or register to view this content. Registration is FREE
|

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
sukantab is offline
Reply With Quote
View Public Profile
 
Old 02-14-2007, 02:04 AM Re: Number guess
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
If you need that many comments to figure out what's going on in the code, you aren't that good a coder. You should be able to deconstruct it and the other coder should be able to define functions and subs (depending on the language) with meaningful names.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-14-2007, 05:45 AM Re: Number guess
Skilled Talker

Posts: 58
Trades: 0
He made this for the new javascript coders. Thats why he made comments.
ProgMania is offline
Reply With Quote
View Public Profile
 
Old 02-15-2007, 08:40 AM Re: Number guess
lizard dude's Avatar
Super Talker

Posts: 119
Location: France
Trades: 0
Quote:
Originally Posted by ADAM Web Design View Post
If you need that many comments to figure out what's going on in the code, you aren't that good a coder. You should be able to deconstruct it and the other coder should be able to define functions and subs (depending on the language) with meaningful names.

Yes I agree with you! lol


Quote:
Originally Posted by ProgMania
He made this for the new javascript coders. Thats why he made comments.
The best way to learn Javascript is by understanding what it does... Not people telling you At least that's how I learned
__________________
forum------->
Please login or register to view this content. Registration is FREE
, for people who wants to have a good time ;)
website------>
Please login or register to view this content. Registration is FREE
(might be in construction :D)
Hope you have a great time and that my post is helpfull ;)
lizard dude is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Number guess
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44751 seconds with 12 queries