PDA

For continued disscussion on this topic : How do you use if and else statements with a counter



DONCORLEON78
06-29-2000, 02:50 PM
I was wondering how to use the if and else statement together correctly with a counter variable.

Let's say I had 5 buttons and I must press those buttons in the correct order 1 through five.
How do I make it so that if button 2 is pressed before 1, or 3 is pressed before 2 the user will get an alert.
Is there a way to set a variable to a counter that increases which in turn would let the browser know the correct order.

Or is there another way that would be better to accomplish this.


Also,
Do you have any pages that focus on explaining the if and else statements and making variables increase kind of like a counter.

Help would be greatly appreciated.

Michel
06-29-2000, 03:17 PM
Here you go:

<SCRIPT>
var count = 1;
function checkOrder(i) {
if(i != count) {
alert("Wrong order!");
count = 1;
return;
}
else
count++;
if(count == 6)
count = 1;
}
</SCRIPT>
<BODY>
<FORM>
<INPUT TYPE="button" VALUE="B1" onClick="checkOrder(1)"><P>
<INPUT TYPE="button" VALUE="B2" onClick="checkOrder(2)"><P>
<INPUT TYPE="button" VALUE="B3" onClick="checkOrder(3)"><P>
<INPUT TYPE="button" VALUE="B4" onClick="checkOrder(4)"><P>
<INPUT TYPE="button" VALUE="B5" onClick="checkOrder(5)">
</FORM>
</BODY>

[Edited by Michel on 06-30-2000 at 03:39 AM]

DONCORLEON78
07-05-2000, 05:46 PM
IS THE LAST CODE POSTED CORRECT BECAUSE I COULD NOT SEEM TO GET IT TO WORK.

AM I DOING SOMETHING WRONG OR DOES THE CODE HAVE A MISTAKE?

DONCORLEON78
07-05-2000, 06:37 PM
sorry.
i got it working.
it was the correct code.

Vincent Puglia
07-05-2000, 08:54 PM
Hi Don,

Check your caps lock when posting; make sure it's off.
Otherwise, someone might think that you were shouting.
I know you weren't :)

Vinny

Arielladog
07-05-2000, 10:24 PM
Yes...people tend to get upset when someone is "shouting"...(thinking of incident happening to him at WSAbstract forum, recently) :)

DONCORLEON78
07-06-2000, 01:17 PM
My apologies. I was in a rush and forgot to turn my caps off.

Vincent Puglia
07-06-2000, 01:27 PM
Hi Don,

no prob :)
so, how is the launching going? You got a url I can peek at?

Vinny