Comp 101 Tamagotchi Beats Part 0

Beats and Tamagotchis -- Intro and Part 0

In this problem set, you will use code to create two fun applications, a beatboxer and a tamagotchi. Here is an overview of what you will do in each part:

1. (Part 0, 25 pts) Beatboxer App: A program that prompts for three sounds and prints them under different conditions in a while loop, making a bopping stream of 50 sounds. 

2. (Part 1, 75 pts) Tamagotchi Pet: A program that acts as a tamagotchi! Play and feed it or your digital pet will die of sadness or hunger.

By the end of this problem set, you will be able to beatbox to your own digital pet and practice the following concepts:

1. Gain comfort and familiarity using while loops

2. Gain comfort and familiarity using if-then-else statements

3. Practice using nested if-then-else statements

4. Learn the concept of remainder division and apply it

Part 0. Starting the Dev Environment

As with in lecture, begin by opening up VSCode, ensuring your project is still open, and then running the following two commands in the VSCode Integrated Terminal:

  1. npm run pull
  2. npm start

Part 1. Setting up an App

In the same directory used in lecture:

  1. Right click on the "src" folder
  2. Select "New Folder"
  3. Name the new folder: ps04-tamagotchi-beats
    1. Note: capitalization and punctuation are important!
  4. Right click on the ps04-tamagotchi-beats folder
  5. Select "New File"
  6. Name the new file: 00-beatbox-app.ts
    1. Note: capitalization and punctuation are important!

* The folder ps04-tamagotchi-beats will eventually contain the two files (corresponding to the two parts) you work in for this problem set. Don’t worry -- we’ll create the tamagotchi file at the beginning of Part 1.

Part 2. Starting your Code

2.0 Honor Code Header

All problem sets begin with an Honor Code pledge. Notice this header is contained within block comment tags discussed in Lecture 1. You can copy paste the pledge below and fill in your name and ONYEN.

/*
* 
* Author: 
* 
* ONYEN: 
* 
* UNC Honor Pledge: I certify that no unauthorized assistance has been received 
* or given in the completion of this work. I certify that I understand and 
* could now rewrite on my own, without assistance from course staff, 
* the problem set code I am submitting. 
*/

2.1 Imports

The next step after ensuring the honor code header is to import the functions we'll use from the introcs library. The first line of code to add to your app is the following:

import { print, promptNumber, promptString } from "introcs";

2.2 The main Function

Your program's execution will begin in a special function named `main`. Inside this function, you will put all of your code. It will run once main is called (main();).

export let main = async () => {   
// TODO: Put all of your code here
};
main();

Part 3: Beatboxer App

In this program you will use a while loop to print sounds provided by the user at specified intervals. 

Part 3.1: Prompt for beatboxer name

With the string "What is your beatboxer name?", prompt the user for a beatboxer name and store it in a variable called beatboxerName.

Part 3.2: Prompt for sounds

Our beat boxing app with play three sounds intermittently, so you need to prompt the user for the three sounds they want to make up their beat stream. 

Declare three variables: sound1, sound2, and sound3, and assign each the value of prompting for a sound (this is a string).

Part 3.3: Create an empty while loop

Remember, there are three steps to making a while loop: 

(1) declare and initialize a counter

(2) define a looping condition

(3) increment the counter. 

Making sure to do all three of these steps, create an empty while loop that should continue to loop as long as a counter variable is less than 50. Name your counter and give it an initial value of 0.

Part 3.4: Create the body of the loop

In the repeat block of the loop, we want to print sound3 if the counter is divisible by 5, print sound2 if the counter is divisible by 3, and print sound1 otherwise. How do we check if is perfectly divisible by 5 or 3? We can use the remainder operator, which is denoted by the percent sign (%)

The remainder operator finds the remainder after the division of one number by another. In other words, the remainder is 0 if a dividend is perfectly divisible by a divisor. Another way to think about it is analogous to dividing a group into a certain number of teams. Say you have 20 people and you are trying to make teams of 3. How many people do you have left over? You can make 6 teams of 3, which leaves 2 people without a team. 

                               So, 20 % 3 = 2

As you can see, we can make expressions with the remainder operator just like we do with division, multiplication, addition, and subtraction. The following are some more examples:

                                10 % 2 = 0

                                11 % 2 = 1

                                44 % 5 = 4

Inside your while loop, use if-then-else statements to print one sound per loop under the following conditions:

a) if is perfectly divisible by 5 (% 5 is 0), print sound3 

b) else if is perfectly divisible by 3, print sound2

c) if neither of the two previous conditions hold, print sound1 

You're done with your while loop! Just be sure to increment your counter by 1 in the last line of the loop (unless you want to create an infinite loop that will destroy your computer)!

Part 3.5: Give the beatboxer credit

Every beatboxer needs to announce the beginning and end of his or her performance. 

Before the while loop, print the beatboxer's name that you prompted for, concatenated to the string " comin' to ya live!"

After the while loop, print the beatboxer's name concatenated to the string " drops the mic!"

Run your app and you should see a stream of 50 beats printed out on the screen. Now try beatboxing your creation with a friend! 

Congrats: you've made a digital beatboxer!

Part 3.6: Publish your app.

With your program running in your web browser, find the green "Publish App" button. If you are not still logged into introcs.com, you will be prompted to log in, and then your app will be bundled and published to the web!

Part 3.7: Submit for grading

To submit for grading, first publish your project as per Part 3.6. Then, go to My101 in the top-right right corner of this page and select "Submit" next to the assignment. From here you should see a button that allows you to submit for grading. Your work will be graded through an automated process. If you receive points off, please select the "Report" link to see which tests did not pass. You can resubmit as many times as you'd like without penalty up until the deadline. We want you to keep working toward full credit on problem sets!

Now you are ready to make a Tamagotchi!