dhmyers82 Posted January 31, 2015 Share Posted January 31, 2015 I need help debugging some homework.I have narrowed the problem down to the switch. when it gets to the switch it is spitting out the default everytime, also in the default the $score in both echo statment is not showing. Its probably something small killing me I just can't see it and dont have enough experience with php yet. <body> <?php $faceNamesSingular = array("one", "two", "three", "four", "five", "six"); $faceNamesPlural = array("ones", "twos", "threes", "fours", "fives", "sixes"); function checkForDoubles($die1, $die2) { global $faceNamesSingular; global $faceNamesPlural; $returnValue = false; if ($die1 == $die2) { //Doubles echo "The roll was double ", $faceNamesPlural[$die1-1], ".<br />"; $returnValue = true; } else { // Not Doubles echo "The roll was a ", $faceNamesSingular[$die1-1], " and a ", $faceNamesSingular[$die2-1], ".<br />"; $returnValue = false; } return $returnValue; } function displayScoreText($scores, $doubles) { switch ($score) { case 2: echo "You rolled snake eyes!<br />"; break; case 3: echo "You rolled a loose deuce!<br />"; break; case 5: echo "You rolled a fever five!<br />"; break; case 7: echo "You rolled a natural!<br />"; break; case 9: echo "You rolled a nina!<br />"; break; case 11: echo "You rolled a yo!<br />"; break; case 12: echo "You rolled boxcars!<br />"; break; default: if ($score % 2 == 0) {//any even number if ($doubles) { echo "You rolled a hard $score!<br />"; } else { //Not Doubles echo "You rolled an easy $score!<br />"; } } break; } } $dice = array(); $dice[0] = rand(1,6); $dice[1] = rand(1,6); $score = $dice[0] + $dice[1]; echo "<p>"; echo "The total score for the roll was $score.<br />"; $doubles = checkForDoubles($dice[0], $dice[1]); displayScoreText($score, $doubles); echo "</p>"; ?> </body> </html> DiceRoll.php Quote Link to comment https://forums.phpfreaks.com/topic/294286-homework-debug/ Share on other sites More sharing options...
Solution mac_gyver Posted January 31, 2015 Solution Share Posted January 31, 2015 your function definition is using $scores as the parameter variable name. your switch() statement is using $score if you set php's error_reporting to E_ALL and display_errors to ON in your php.ini, php would have been throwing an undefined variable error at the $score usage that would have pointed you toward the problem. Quote Link to comment https://forums.phpfreaks.com/topic/294286-homework-debug/#findComment-1504435 Share on other sites More sharing options...
dhmyers82 Posted January 31, 2015 Author Share Posted January 31, 2015 Thank you, I knew it was going to be something stupid like that. Quote Link to comment https://forums.phpfreaks.com/topic/294286-homework-debug/#findComment-1504438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.