commit 0f160c8cf1a217710d024f54d7a39cb73f871ac7
parent d6dcaa447be7934266cb9e3404a94c57c7634a07
Author: Samir Parikh <noreply@samirparikh.com>
Date: Thu, 17 Feb 2022 02:49:27 +0000
complete process_guess subroutine
Diffstat:
1 file changed, 15 insertions(+), 0 deletions(-)
diff --git a/guess_number.cgi b/guess_number.cgi
@@ -54,6 +54,19 @@ sub process_guess {
return ("Sorry, you ran out of turns. The number was $state->{NUMBER}.",
'lost') unless ($state->{GUESSES_LEFT} && $guess != $state->{NUMBER});
+ # guess too low
+ return ("Your guess is too low.", 'continue')
+ if ( $guess < $state->{NUMBER} );
+
+ # guess is too high
+ return ("Your guess is too high.", 'continue')
+ if ( $guess > $state->{NUMBER} );
+
+ # guess is correct!
+ return ("Congratulations! You guessed that the correct number
+ was $state->{NUMBER}!", 'won')
+ if ( $guess == $state->{NUMBER} );
+
}
@@ -69,3 +82,5 @@ if ( !$state || $game->param( 'restart' ) ) {
# process current guess, if any
my ( $message, $status ) =
process_guess( $game->param( 'guess' ) || '', $state );
+
+# generate the HTML page