...

View Full Version : student --guessing game script problems



wolfy
11-09-2004, 12:18 AM
:confused: I am working on a homework assignment that asks as a guessing game. The user inputs numbers in a box and clicks the submit button to see if it is right. If it is correct, then an alert is displayed, if not an alert is also displayed. There is a 10 second timer that displays a confirmation box to continue or quit the game. If not responded by the 10 second timer the window closes.
or if the use clicks ok then user is returned to the game.

I would appreciate it if someone could tell me where I went wrong.
Not looking for someone to do my work, just to explain what I am not doing correctly. I fixed the brackets and get no errors but still don't work.
How do I get the alerts to show up?
Thanks.
Here is my script:

<HTML>
<HEAD>
<TITLE>Guess Number</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
var number=7;
function returnAnswer() {
if (number == 7) {
alert("You are correct!");
Else (number != 7);
alert("Try again!");
}
function confirmation() {
return confirm("Do you want to stop the game?");
if (confirmation == true){
setTimeout("window.close, 10000");
Else (confirmation == false);
open("GuessNumber.html");
}
}
// STOP HIDING FROM IMCOMPATIBLE BROWSERS -->
</SCRIPT>
</HEAD>
<BODY>
<H1>The Guessing Game</H1>
<FORM NAME="game">
<INPUT TYPE="text" NAME="number" SIZE="2">
<INPUT TYPE="bUTTON" NAME="Guess" VALUE="Guess" onClick="returnAnswer">
</FORM>
</BODY>
</HTML>
confused: thanks for the help guys, but still got a problem

c1lonewolf
11-09-2004, 01:20 AM
your if's and else's need to be contained in braces
function my(){
if(number==7){
//do this
}
else{
//do this
}
}

Garadon
11-09-2004, 07:01 AM
since your a student here is a friendly advise use indentation in ur code makes it easier to read:


function something(){
*kode*
if(){
*kode*
}
else
{
*kode*
}
}

wolfy
11-14-2004, 02:44 PM
I am working on a homework assignment that asks as a guessing game. The user inputs numbers in a box and clicks the submit button to see if it is right. If it is correct, then an alert is displayed, if not an alert is also displayed. There is a 10 second timer that displays a confirmation box to continue or quit the game. If not responded by the 10 second timer the window closes.
or if the use clicks ok then user is returned to the game.

I would appreciate it if someone could tell me where I went wrong.
Not looking for someone to do my work, just to explain what I am not doing correctly. I fixed the brackets and get no errors but still don't work.
How do I get the alerts to show up?
Thanks.
Here is my script:

<HTML>
<HEAD>
<TITLE>Guess Number</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
var number=7;
function returnAnswer() {
if (number == 7) {
alert("You are correct!");
Else (number != 7);
alert("Try again!");
}
function confirmation() {
return confirm("Do you want to stop the game?");
if (confirmation == true){
setTimeout("window.close, 10000");
Else (confirmation == false);
open("GuessNumber.html");
}
}
// STOP HIDING FROM IMCOMPATIBLE BROWSERS -->
</SCRIPT>
</HEAD>
<BODY>
<H1>The Guessing Game</H1>
<FORM NAME="game">
<INPUT TYPE="text" NAME="number" SIZE="2">
<INPUT TYPE="bUTTON" NAME="Guess" VALUE="Guess" onClick="returnAnswer">
</FORM>
</BODY>
</HTML>
confused: thanks for the help guys, but still got a problem!

codegoboom
11-14-2004, 04:21 PM
Let's see...


var number=7;
...

<INPUT TYPE="text" NAME="number" SIZE="2">

These should be named differently



var number=7;
function returnAnswer()
{
if (number == 7)
{
alert("You are correct!");
Else (number != 7);
alert("Try again!");
}

The logic is flawed.
Your braces are wrong.
JavaScript is case sensitive.
This does nothing, and screws up the conditional.


function confirmation()
{
return confirm("Do you want to stop the game?");
if (confirmation == true)
{
setTimeout("window.close, 10000");
Else (confirmation == false);
open("GuessNumber.html");
}
}


That's a problem.
Nothing calls this function
close is missing parentheses "window.close()"
your braces are wrong.
JS is case sensitive.
Your else statement is messed up again.



<INPUT TYPE="text" NAME="number" SIZE="2">
<INPUT TYPE="bUTTON" NAME="Guess" VALUE="Guess" onClick="returnAnswer">


Your function call is missing parentheses.
You are not getting the value of the number input.
You will have to convert that from string to number.
correction: in this case, the string wouldn't need to be converted...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum