Jump to content

illadelphiakid

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by illadelphiakid

  1. Uhh nvm i spelled something wrong. i get this Array ( [word_defs] => To recant, renounce, repudiate under oath. [guess] => Guess [word] => abjure ) Array ( )
  2. I get an error trying to print session but printing get, i receive this: Array ( [word_defs] => To recant, renounce, repudiate under oath. [guess] => Guess [word] => abjure ) The word and def are correct, but response says incorrect.
  3. Please help, i'm writing a code that a user must match a random word ($word) from a choice of definitions ($word_defs)...No matter what definition is picked from the list, the response is always 'incorrect', can someone please look at my code and tell me what's wrong? Here is the entry code: require_once "include/word_defs.php"; $word = array_keys($word_defs); $word_defs = array_unique(array_values($word_defs)); $session = new Session(); $params = (object) $_REQUEST; if (isset($params->guess)) { $word = $params->word; if ( $params->word_defs == $word_defs[$word] ) { $response = "correct"; } else { $response = "incorrect"; } $choices->word_def[$params->word_defs] = "selected"; } else { $word = $word[ rand( 0, count($word)-1 ) ]; } Code in body: word: <?php echo $word ?> <form action="?" method="get"> definition: <select name="word_defs"> <?php foreach ($word_defs as $word_def): ?> <option <?php echo $choices->word_def[$word_def] ?> ><?php echo $word_def?></option> <?php endforeach ?> </select> <input type="submit" name="guess" value="Guess" /> <input type="hidden" name="word" value="<?php echo $word?>" /> </form> <h3><?php echo $response ?></h3>
  4. Sorry i meant that it always relaying that the user is INCORRECT, and also how do i sticky the definitions?
  5. The code here is suppose to allow the user to match up a word ($word) with a list of definitions ($word_defs). I can't get the list of definitions to stick. When the user does make a guess it shows that he is always correct. How can i fix these problems? Outside entry code: <?php require_once "include/session.php"; require_once "include/word_defs.php"; $word = array_keys($word_defs); $word_defs = array_unique(array_values($word_defs)); $params = (object) $_REQUEST; $session = new Session(); if (isset($params->guess)) { $word = $params->word; if ( $params->word == $word_defs[$term] ) { $response = "correct"; } else { $response = "incorrect"; } $choices->word_def[$params->word_def] = "selected"; } else { $word = $word[ rand( 0, count($word)-1 ) ]; } ?> Body code: word: <?php echo $word ?> <form action="?" method="get"> definition: <select name="word_defs"> <?php foreach ($word_defs as $word_def): ?> <option <?php echo $choices->word_def[$word_def] ?> ><?php echo $word_def?></option> <?php endforeach ?> </select> <input type="submit" name="guess" value="Guess" /> <input type="hidden" name="word" value="<?php echo $word?>" /> </form> <h3><?php echo $response ?></h3>
  6. I'm trying to get this drop down menu to be sticky once the user clicks submit. Here's my entry code: if (isset($_POST['guess'])) { if ($_POST['guess'] == $_SESSION['number']) { $response = "You Win!"; unset($_SESSION['number']); } else { $_SESSION['tries']++; if ($_SESSION['tries'] < 3) { $response = "Try #{$_SESSION['tries']}<br /><br />"; } else { $response = "You Lose"; unset($_SESSION['number']); } } } if (empty($_SESSION['number'])) { $_SESSION['tries'] = 0; $_SESSION['number'] = rand(1, 10); } And in my body: <select name="guess" id="guess"> <?php for ($i = 1; $i < 11; $i++) { echo "<option value='{$i}'>{$i}</option>"; } ?> </select>
  7. Can someone help me create this?? Upon outside entry, a random number is chosen between 1 and 10. Use this function to generate the guess number $guessnum = rand(1,10); // you may change the variable name The user tries to guess this number by choosing from a selection list of possibilities. The user "loses" if there are three failed attempts. For reentrant activations the selection list must be sticky and the same guess number must be maintained. The guess number and the attempt number must both be propagated through hidden inputs. Here is a screen shot: Upon outside entry, or using the "Start Over" hyperlink (with the list activated): Let's suppose the number to be guessed is 6. I select 4 and guess it. Response should say "Try #1" I select 9 and guess it. Response should say "Try #2" I select 3 and guess it. Response should say "You Lose" At this point assume that we must "Start Over". This time, suppose the generated number is 8. I select 8 and guess it. Response should say "You Win" Again, assume we must "Start Over".
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.