The 2008 Winter Scripting Games

Beginner Event 8: Random Guess

Important: The deadline for this event has passed. Solutions are available in VBScript, Windows PowerShell, and Perl.

In Random Guess, competitors will be asked to generate a random number and allow the user to try to guess that number.

Not a native speaker of English? These event instructions are also available in the following languages: Chinese (Simplified); Chinese (Traditional); French; German; Japanese; Portuguese Brazilian; Russian; and Spanish. For more information, and to access these localized instructions, see the Scripting Games International page.

*
On This Page
About This EventAbout This Event
Event ScenarioEvent Scenario

About This Event

Division

Beginner

Deadline

Thursday, February 28, 2008 (8:00 AM PST)

Points Awarded

15

Top of pageTop of page

Event Scenario

This event is a little different depending on which division you’re competing in. If you’re competing in the VBScript division you’ll be creating an HTML Application (HTA). If you’re competing in Windows PowerShell or Perl you’ll be using a standard command-line script.

For this event you’ll be creating a game. Okay, maybe not the most interesting game you’ve even seen (hey, this is the Beginner’s Division after all), but a game nonetheless. In this game, your script will generate a random number between 1 and 50, and the user will be required to guess that number.

VBScript

Create an HTA with the title Random Guess that contains: 1) some text asking the user to enter a number; 2) a text box; and 3) a button labeled Guess. Your HTA should look something like this:

Random Guess Request Input

When the HTA starts, it should generate a random number (integer values only) between 1 and 50. After the user enters a number and clicks the Guess button, the HTA should display a message box indicating whether the person guessed the random number correctly. If they guessed incorrectly, the message box should tell them whether the guess was too high or too low:

Random Guess Too Low

After they dismiss the message box the user will be allowed to make another guess. When the user guesses the number correctly, the HTA should display a message box that shows the random number and the total number of guesses it took to reach the correct number. Something like this:

Random Guess End

After they click OK, the game is over, which means the script needs to close the HTA window.

Windows PowerShell/Perl

For Windows PowerShell and Perl this will be a standard command-line script. The script will display a message asking the user to enter a number between 1 and 50. The script will compare the number supplied by the user to a randomly-generated number. If the numbers don’t match, the script will display a message indicating whether the guess was too high or too low and ask them to guess again.

When the user guesses correctly, the script will display the random number and the number of guesses it took to reach the correct number. At that point the game is over, so the script will end.


Top of pageTop of page