# Assignment 3.2: Number Guessing Game

## Objectives

The goal of this assignment is to learn the following:

- Conditionals and lexical scoping
- Loops
- How to analyze a problem statement

## Computer Science Principles Curriculum

**Big Idea: Algorithms:**EU 4.2, LO 4.2.3, EK 4.2.3A, EK 4.2.3B, EK 4.2.3C**Big Idea: Algorithms:**EU 4.2, LO 4.2.4, EK 4.2.4A, EK 4.2.4B, EK 4.2.4C, EK 4.2.4G**Big Idea: Programming:**EU 5.4, LO 5.4.1, EK 5.4.1M, EK 5.4.1N

## Common Core Standards

**English Language Arts Standards ยป Science & Technical Subjects:**CCSS.ELA-Literacy.RST.9-10.3, CCSS.ELA-Literacy.RST.9-10.4, CCSS.ELA-Literacy.RST.9-10.5, CCSS.ELA-Literacy.RST.9-10.7, CCSS.ELA-Literacy.RST.9-10.10, CCSS.ELA-Literacy.RST.11-12.2, CCSS.ELA-Literacy.RST.11-12.3, CCSS.ELA-Literacy.RST.11-12.4, CCSS.ELA-Literacy.RST.11-12.5, CCSS.ELA-Literacy.RST.11-12.10**Standards For Mathmatical Practice:**CCSS.Math.Practice.MP1, CCSS.Math.Practice.MP2, CCSS.Math.Practice.MP4, CCSS.Math.Practice.MP5, CCSS.Math.Practice.MP6, CCSS.Math.Practice.MP7, CCSS.Math.Practice.MP8

## Vocabulary

- Conditional
- Lexical Scoping
- Random Number
- Repeat Loop

## Overview

In this assignment you will write a program using the skills you have already learned. Write a number guessing game that generates a random number between 1 and 100, inclusively (meaning 1 and 100 should be included). Once a number is generated, ask the user to guess that number and continue asking the until they guess the correct number. You will give the user hints, such as telling them their guess is too high or too low.

## Complete the Following Tasks to Meet All Objectives

Create a new project and name it **GuessingGame**, and open the main.quorum file.

Your program should:

- Use a repeat loop, so the game will continue until the game is over.
- Have a conditions to determine if the users guess is less than, greater than, or equal to the random number.
- Ask the user to enter a number between 1 and 100.

**Example: use statement and RandomIntegerBetween(integer, integer) action you will need.**

You will need to use

`Libraries.Compute.Random`

to create a random number object. You will then need to call the `RandomIntegerBetween(integer, integer)`

action on that object.```
//This line is the use statement.
```

use Libraries.Compute.Random

//Add your Random object here.
Random random
//Call this action on your Random object. Fill in the parameters with the correct integers.

random:RandomIntegerBetween(integer, integer)

**NOTE: Output and the Online Editor**

When running this assignment online, the results of `output`

won't appear until after the program finishes. This means that if we use `output`

statements to let the user know if their guess is too low or too high, they won't get any feedback until after they've already guessed correctly. To get around this problem, we can add our output to the beginning of our `input`

statements instead.

```
// We can store our "output" in this variable.
```

text response = "Welcome to the number guessing game. Can you guess my number?"

// Then we can add our variable to the front of our input statement.

integer guess = cast(integer, input(response + " Guess a number between 1 and 100:"))

## Sample Output

The input dialog statements are included in the sample output. They are identified as [Input Dialog].

```
Welcome to the number guessing game. Can you guess my number?
[Input Dialog] Guess a number between 1 and 100: 50
My number is less than 50
[Input Dialog] Guess a number between 1 and 100: 25
My number is greater than 25
[Input Dialog] Guess a number between 1 and 100: 38
You guessed my number!
Game over.
```

## Next Tutorial

In the next tutorial, we will discuss Assignment 3.3, which describes Key Press Madness - Audio in Quorum..