[SOLVED] Help with guess a number program

This is a discussion on "[SOLVED] Help with guess a number program" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Help with guess a number program are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Oct 13th, 2007, 22:49
New Member
Join Date: Oct 2007
Location: New York
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Help with guess a number program

I need help with this Guuess a number program> Its probly easy for for you but I'm brand new at this javascript stuff. Antways here what i got make work and what I have got so far.


Guess a number program- The user will pick a number from 1 to 1000. Your program should guess the user number in ten tries or less.After each guess the user will specify if the guess is low or high or correct.


This what I have so far.

HTML: Select all
<html>
<head></head>
<title>Guess your interger</title>
<script language = "javascript">
 
function Math.Round(high+low)/2(){
Var highnum=1000; 
var lownum=0;
var guess =(lownum+highnum)/2;
var count=0;
 
 
 if (myform.High.Checked)
 highnum=guess} 
 
 
 
 if (myform.Low.Checked){
 lownum=guess}
 guess=(lownum+highnum)/2
 count++
myform.guessbox.value=guess
myform.counter.value=guess
 
 
}
</script>
<body>
<H1><bold><center> Guess Your Integer</h1>
<h3> Think of an interger between 1and 100(Don't tell anyone!)<br>
The computer will guess you number in ten guesses or less<br><br><br>
Check high checkbox if our guess was to high
<br>
Check Low checkbox if our guess was to low
<br>
Press Guess button to start game.
<br>
<br>
<br>
<Form name = "myform">
<input type="button" value="Guess"onclick="Math.Round(high+low)/2()">
<p>Low<INPUT TYPE = "Checkbox" name = "Low">
<p>High<INPUT TYPE = "Checkbox" name = "High">
<p>Our guess is<input name = "guessbox" type="text">
<p>We have made<input name= "counter" size="8">Guesses 
 
</form>
</head>
</body>
Thank for the help

Last edited by Rakuli; Oct 13th, 2007 at 22:54. Reason: Please use [html][/html] BBC when placing code. Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 14th, 2007, 09:29
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Help with guess a number program

OK, to start with let's get rid of your syntax errors:
- Your function name was not valid.
- You were missing a '{' at the beginning of the first IF statement.
- I know that you don't have end each line with a semicolon, but it's good programming practice to do so.

So, here is your corrected code:
HTML: Select all
<html>
<head></head>
<title>Guess your interger</title>
<script language = "javascript">
function Guess() {
    var highnum=1000; 
    var lownum=0;
    var guess =(lownum+highnum)/2;
    var count=0;

    if (myform.High.Checked) {
        highnum=guess;
    } 

    if (myform.Low.Checked){
        lownum=guess;
    }
    
    guess=(lownum+highnum)/2;
    count++;
    myform.guessbox.value=guess;
    myform.counter.value=guess;
}
</script>
<body>
<H1><bold><center> Guess Your Integer</h1>
<h3> Think of an interger between 1and 100(Don't tell anyone!)<br>
The computer will guess you number in ten guesses or less<br><br><br>
Check high checkbox if our guess was to high
<br>
Check Low checkbox if our guess was to low
<br>
Press Guess button to start game.
<br>
<br>
<br>
<Form name = "myform">
<input type="button" value="Guess"onclick="Guess()">
<p>Low<INPUT TYPE = "Checkbox" name = "Low">
<p>High<INPUT TYPE = "Checkbox" name = "High">
<p>Our guess is<input name = "guessbox" type="text">
<p>We have made<input name= "counter" size="8">Guesses 

</form>
</head>
</body>
Your next problem is that you have a bunch of logic errors. The way this page is written right now, it won't work... I'm not going to write this one for you, but I'll give you some hints:
- the highnum, lownum, count, and guess variables need to be declared and initialized outside of the Guess() function.
- the value of the 'counter' input box should be "counter" and not "guess" .

Good Luck and if you really get stumped, feel free to ask some more questions.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 14th, 2007, 14:51
New Member
Join Date: Oct 2007
Location: New York
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Help with guess a number program

Thanks for the help Your Hints and correction are greatly apreciated
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

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
[SOLVED] Insert new row without knowing number of columns?? nate2099 Databases 2 Dec 27th, 2007 03:51
[SOLVED] IP Number Stormraven Webforumz Cafe 2 Nov 10th, 2007 20:30
Guess What Daniel Webforumz Cafe 9 Feb 27th, 2007 20:20


All times are GMT. The time now is 23:41.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42