Please enable JavaScript to use CodeHS

Mastermind

In this project, students will recreate the classic game of Mastermind using loops, conditional statements, and lists.

Hard

5 Hours

High School

Project Description

Background

In this project, students will be writing the code to simulate the popular game of Mastermind. Mastermind is a two-person code breaker game where one person creates a code and the second person tries to break it.

In this version of the game, the computer will be creating the code and the user will be trying to break it.

Your Task

Through a series of activities, you will create the game. You start by first creating a list of numbers following these requirements:
1. The list is 4 numbers long
2. Randomly assign the values 1-7 to the list items.
3. Each number can only appear once, so check to make sure there are four unique numbers in the list.

You will then write the code to get the user’s guess, process that guess, and determine if the user wins or loses.

Project Demo

Explore this program before assigning it!