🚀 Basics Day 2: In-Class Exercises 🚀

Pre-Class In-Class

Base: Lucky 11

Create a dice game that allows a user input a guess number and roll 2 dice when the Submit button is clicked. The user wins if:

  1. One of the dice roll matches their guess, or
  2. If the total dice roll is 11.

Otherwise the user loses.


Input a guess number:


Output:

Base: Hawker Food Categorisation

Hawker food is a convenient and affordable food option in Singapore. To help educate non-Singaporeans about hawker food, create an app that takes a hawker dish name as input, and tells users whether the dish has a "rice", "noodle", or "other" base. Some sample dishes are: "chicken rice", "roti prata", "nasi lemak", "hokkien mee", "bak kut teh", and "laksa".

For example, if a user enters "laksa", the program should output "noodle". If a user enters "roti prata", the program could output "other".

Please use the || operator.


Enter the name of a dish:


Output:

Comfortable: 4D with Single-Digit Comparison

4D is a popular betting game in Singapore run by Singapore Pools. Rocket Academy does not endorse gambling.

Create a version of 4D where the player wins if their guess matches any of the 4 digits. The player will input a single digit, and the computer generates 4 random digits between 0 and 9. If the player-inputted digit matches any of the randomly-generated digits, the player wins.

In addition to the win/loss result, output the player guess and all randomly-generated digits so the player can see how close they were.


Guess a single-digit number:


Output:

Comfortable: Hawker Food Randomness

The uncle at your favourite hawker stall has decided to challenge himself and serve a random hawker dish to each customer. The dishes in his repertoire are: "chicken rice", "roti prata", "nasi lemak", "hokkien mee", "bak kut teh", and "laksa". Customers that correctly guess Uncle's dish receive a free meal.

Create an app that uses random numbers to help Uncle decide which dish to cook. The customer can only input dish names. If the customer correctly guesses Uncle's dish, let her know that she gets a free meal!


Enter the name of a dish:


Output:

More Comfortable: 4D with Winning Range

Create a version of 4D where the player wins if they guess within 1000 (above or below) of the winning 4-digit number. Consider using comparison operators such as less than (<) and greater than (>).


Guess a number:


Output:

More Comfortable: Hawker Food Omakase

Uncle has decided to serve an omakase option, and output a menu based on customer input.

  1. Customers can input either "rice" or "noodle", and Uncle will choose either 2 random rice or 2 random noodle dishes for them. Assume Uncle's rice dishes are "chicken rice", "nasi lemak", and "bak kut teh", and Uncle's noodle dishes are "hokkien mee", "laksa", and "beef hor fun".
  2. Roti prata is neither rice nor noodle, but Uncle can randomly choose to include it as one of the two dishes if he feels like it.
  3. Uncle charges more for omakase and uses premium descriptions for his dishes. Feel free to get creative. To create a new line in the output box you can use the string '<br>', which generates a new line in HTML output.
  4. Output at the end if sambal is included. Not all dishes come with sambal, for example roti prata and bak kut teh don't come with sambal.

Enter either "rice" or "noodle":


Output: