Hello all,
I've got a couple of textboxes where users enter answers to questions.
31. Write the <b>first name</b> of one student who //passed// the session:
<<textbox "$q41" "">>
32. Write the <b>first name</b> of one student who //failed// the session.
<<textbox "$q42" "">><<button [[Submit|Partner Finalize FGR 3]]>><</button>>
The user has the answers, and can enter them in. There are several possible answers to each question, so I'm checking like this:
<<if $q41 eq "Shannon" or $q41 eq "Muriel" or $q41 eq "Marion" or "Debra" or $q41 eq "Ira" or $q41 eq "Wendell" or $q41 eq "Kelly" or $q41 eq "Peter" or $q41 eq "Aubrey" or $q41 eq "Perry" or $q41 eq "Troy">>
<<if $q42 eq "Rosie" or $q42 eq "Allen" or $q42 eq "Marguerite">>
<<set $player.experience to $player.experience + 5>>
<else>>Nope! <<back>><<audio "error" play>>
<</if>>
<</if>>
I originally had it setup as one <<if>> conditional with "and" between $q41 and $q42, but that didn't work either. The problem is that if I enter any two names listed in either textbox, the result is accepted as correct and experience is gained by the player.
For example, if I enter Rosie in $q41 textbox and Allen in the $q42 textbox, (One value incorrect, one value correct) the answers are counted as correct and experience is awarded.
On the other hand, if I enter Rosie in $q41 and Shannon in $q42, (meaning both values are incorrect for the accepted answers), it returns a false value. Is there a way that I can more accurately assess the validity of both variables, instead of just one?
Thank you!
Comments
A somewhat easier to read alternative would be to use two temporary variables to hold arrays of the valid answers and the <Array>.contains() method to search them for the given answers. For example:
I did it the way you first suggested and got mixed results. Here's what I entered in each textbox and the result:
- $q41 true, $q42 true, returns true
- $q41 blank, $q42 true, returns true
- $q41 false (random text input), $q42 true, returns true
- $q41 true, $q42 blank, returns false
- $q41 true, $q42 false (random text input), returns false
- $q41 false, $q42 false, returns false
It seems like the logic is looking only at whether or $q42 is true, and is almost ignoring $q41. Any ideas why this may be? Thanks again for all your support.
Errors like that are one of the reasons I suggested using arrays.