PHP Number Guessing - adding input control - project won't save

This question is for https://www.codecademy.com/courses/learn-php/projects/php-number-guessing

My code is shown below, I was trying to refactor it make it a bit less lengthy. I’ll break the issue down first.

Within the guessNumber function a while loop checks the $play_count variable is less than 10.
Within the while loop an if/else conditional checks the input from readline falls between 1 and 10 (inclusive).
BUT - when I try to increment $play_count inside the while loop (instead of in the main body of the function) the project won’t save and can’t be tested. It’s like the console can’t see that the $play_count variable is being incremented and the while goes into an infinite loop.

All the effort here is to make sure that the $play_count variable is incremented only when the value matches the if/else statement.
Can anyone tell me what I’m doing wrong? (if you can get the codebyte to run it that is)

Many thanks,
Martin

<?php $play_count = 0; $correct_guesses = 0; $guess_high = 0; $guess_low = 0; echo "Guess the number. \n In each round I will think of a number from 1 to 10.\n The game tracks your guesses and gives some stats on your performance."; function guessNumber(){ global $play_count, $correct_guesses, $guess_high, $guess_low; //Use $play_count to loop the game inside the function while ($play_count < 10){ //Random number generator $target = rand (1, 10); //Player message, inout capture and conversion to INT echo "\nMake your best guess\n"; $answer = intval (readline(">>")); if( $answer < 1 || $answer > 10){ echo "\nPlease only enter a number between 1 and 10.\n"; } else { //Increment $play_count $play_count ++; this line causes the console to reset //Game results message echo "\nRound $play_count\n"; echo "Your guess was $answer\n"; echo "The target number was $target\n"; //Game stats logic if ($answer < $target){ $guess_low ++; echo "Too low, sorry.\n"; } elseif ($answer > $target){ $guess_high ++; echo "Too high!\n"; } else { $correct_guesses ++; echo "You guessed it right. Well done \n"; } } } } guessNumber(); //invoke the function //Calculate percentages $correct_pctg = ($correct_guesses / $play_count) * 100; $high_pctg = ($guess_high / $play_count) * 100; $low_pctg = ($guess_low / $play_count) * 100; //Show them on screen and end game echo "\n*********************************************\n"; echo "That's game over, let's see how you did:\n"; echo "Correct guesses " . $correct_pctg . "%\n"; echo "High guesses " . $high_pctg . "%\n"; echo "Low guesses " . $low_pctg . "%\n"; if ($high_pctg > $low_pctg){ echo "\nWhen you guessed wrong you tended to guess high.\n"; } else { echo "\nWhen you guessed wrong you tended to guess low.\n"; };