Please enable JavaScript to use CodeHS

The Game of Pig

In this project, students will create the game of pig. Students will use functions, conditional statements, and loops as they create a game to compete against the computer.

Medium

4 Hours

Project Description

Background

The Game of Pig is a classic game played with a 6 sided die. In the game a player rolls the die. If they roll a 2 through 6, they add that score to their round score, but if they roll a 1, their round is over and their round score resets to zero.

At any point, the player can choose to bank their round score. When they do that, the points are added to their overall score and their round score resets back to zero.

Once the player’s overall score reaches 100, they win. While the die roll is random, there is a little strategy when deciding whether to bank or continue in the round. If you try to be a pig and get more points, you may lose everything and have to start over!

Your task

In this project, you will build out the game in 2 steps. First, you are going to build a basic one-player version. In the second activity, you will add a computer opponent.

Project Demo

Explore this program before assigning it!

Project Overview

Here is an outline of the project activities: