Comp 101 UNC Basketball Extravaganza Part 0

UNC Basketball Extravaganza

In this problem set, to immerse ourselves in basketball season, you will create two programs related to Carolina Basketball! Start early. You are encouraged to complete each segment and check your work via the grader before continuing on to the next section.

Basketball Scoreboard

For the first part of the assignment, you will make a program that acts as a UNC Basketball Scoreboard. The program will prompt for home and away team scores and then print a statement about who won and with what final scores.

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

The first command "pulls" the latest files needed for COMP101 into your repo, if any. The second command starts the development environment and will open your web browser to the local server. 

Part 1. Setting up an App

  1. Right click on the "src" folder
  2. Select "New Folder"
  3. Name the new folder: ps03-unc-basketball-extravaganza
    1. Note: capitalization and punctuation are important!
  4. Right click on the ps03-unc-basketball-extravaganza folder
  5. Select "New File"
  6. Name the new file: 00-scoreboard-app.ts
    1. Note: capitalization and punctuation are important!

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:
 * 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 importing the functions we'll use from the introcs library (i.e. printpromptNumber, and so on).

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

2.2 The main Function

Your program's logic will begin a function named `main`. All of your code from this point on will go inside its brackets. Here is the incantation to setup your main function:

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

Part 3. UNC Scoreboard 

Now we can start making our scoreboard

Part 3.1: Welcome the user and prompt for away team

Inside the main method, print a welcome statement such as "Welcome to the UNC basketball scoreboard!" 

Next, we need to ask the user what team Carolina is playing. Declare a variable named awayTeam and assign it the value of the result of prompting the user for what team UNC played against. 

Part 3.2: Prompt for current score

Ask the user for the current UNC and away team scores.

a) Declare a variable named uncScore and assign it the value of of prompting the user for UNC's score, using any string as an argument to the prompt.

b) Declare a variable named awayScore and assign it that value of prompting the user for the away team's score. The string argument to the prompt must have the awayTeam variable concatenated to the message. For example, if the away team the user selected was NC State, the prompt should appear on the users's screen as How many points did NC State score?

Part 3.3: Print the winner and scores

Besides just displaying how many points each team scored, our scoreboard will say whether UNC won, lost, or tied. This means you need to print different statements depending on the three scenarios. To do this, you need to use three if-then statements, one for each condition (win, lose, and tie).   

3.3 a) UNC Wins

Our first if-then statement will ask if UNC won. Remember there are two parts of an if-then statement, the "test" and the then block:

if (<"test" - boolean expression>) {
<then block runs when "test" is true>

In our case, we are testing whether UNC's score is greater than the away team's score. IF this evaluates to true THEN you want the following to be printed to the user (with the variables in the <> blocks being concatenated in the print statement):

       UNC beat <awayTeam> <uncScore> to <awayScore>!

For example, if awayTeam, uncScore, and awayScore were NC State, 96, and 89, the following would be printed:

       UNC beat NC State 96 to 89!

3.3 b) Away Team wins

Make another if-then statement that evaluates in the away team won. IF UNC's score is less than the away team's score THEN print the following to the user:

      UNC lost to <awayTeam> <awayScore> to <uncScore>.

3.3 c) The teams tie

Our final if-then statement evaluates if the teams tied. IF UNC's score is equal to the away team's score THEN print the following to the user:

      UNC somehow managed to tie <awayTeam> <uncScore> to <awayScore>.

Congrats you are finished with your scoreboard!

Part 3.4: Publish your app.

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

Part 3.5: Submit for grading

To submit for grading first publish your project. 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 move onto the next part!