Now that you have finished your scoreboard, this program will prompt for information about the current state of a UNC basketball game to calculate the probability UNC has of winning.

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:

- npm run pull
- 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.

- Right click on the
**ps03-unc-basketball-extravaganza**folder you made in Walk - Select "New File"
- Name the new file:
**01-probability-app.ts** - Note: capitalization and punctuation are important!

* The folder **ps03-unc-basketball-extravaganza** should already contain the 00-scoreboard-app.ts file.

**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.

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 *importing* the functions we'll use from the **introcs** library (i.e. *print*, *promptNumber*, 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 }; main();

**Part 3.1: Getting started**

In this part, we will welcome the user (like in the previous program), ask for the away team (also like in the previous program), and create variables to hold the probability points.

3.1 a) Inside the main function, print a welcome statement such as "Welcome to the win probability calculator"

3.1 b) 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 is playing against.

3.1 c) Now we need to create variables to hold "probability points." Throughout this program, we will increase the probability points based on certain conditions. In the end, these will be used to calculate UNC's chances of winning. Declare two variables of type number called *uncProbabilityPoints *and *awayProbabilityPoints *and assign both an initial value of 1.

**Part 3.2: Adjust Probability Points Based on Score**

3.2 a) Prompt the user for UNC and the away team's scores and store the values in two variables called *uncScore *and *awayScore*.

3.2 b) Declare a variable called *scoreDifference *and assign it the value of taking UNC's score minus the away team's score. Notice that this value will be positive if UNC is winning, 0 if they are tied, and negative otherwise. This is important for part c.

3.2 c) In this part, you will add to the winning team's probability points the amount they are winning by (stored in *scoreDifference*). To do this, you need to use if-then statements. If UNC is winning, add *scoreDifference *to UNC's probability points. If the away team is winning, add *scoreDifference *to the away team's probability points. Be sure to remember that the score difference will be *negative* if UNC is losing. This also means that you can simply compare *scoreDifference* with 0 to determine which team's probability points we should be adding to. Think of this part as adding the absolute value of *scoreDifference *to the winning team.

**Part 3.3: Adjust probability points based off time remaining **

In this part, we want to give the winning team more points based on how much time is left in the game. If there is a lot of time left in the game, we will not increase the winning team's probability points by much; however, if there is only a little time left, we will increase the winning team's probability points by a larger factor.

3.3 a) First, we need to ask how much time is left in the game. Prompt the user for the amount of time left in the game (in minutes) and store this in a variable called *timeRemaining*.

3.3 b) Now that we know the time left, we can create a "time factor," or a factor we will multiply with the winning team's score. The following is the equation for the time factor. Notice how it becomes increasingly larger with less time remaining in the game.

** *** timeFactor = 1/(timeRemaining/40*)

Create a variable called *timeFactor *to hold the time factor.

3.3 c) Like 3.2c, you will once again modify the winning team's probability points using if-then statements. Take the winning team's probability points, multiply this value by the time factor, and store this value back into the variable holding the winning team's probability points.

**Part 3.4: Calculating the final win probability**

Now you need to use the probability points to calculate UNC's chances of winning. In this program, UNC's chances of winning are interpreted as the percentage of probability points UNC has out of the combined probability points held by UNC and the away team.

3.4 a) To calculate this percentage, you first must calculate the total number of probability points. Create a variable called *totalProbabilityPoints *and assign it the value of the sum of UNC and the away team's probability points.

3.4 b) Now calculate the ratio of UNCâ€™s probability points to all the probability points by dividing *uncProbabilityPoints *by *totalProbabilityPoints* and then store the result in a variable called *uncWinProbability*. Multiply this ratio by 100 so that we can display it as a percentage.

3.4 c) All that is left is to tell the user UNC's chances of winning. Print the variable you created in 3.4 b so that the output to the user looks like the following (where 27 is the value of *uncWinProbability)*:

* UNC chance of winning: 27%*

**Part 3.5: Example input and output**

To test your code, here are some example prompt responses and resulting probability points.

Test 1:

UNC: 10pts

NC State: 20pts

Mins: 20

UNC chance of winning: 4.3478260869565215%

Test 2:

UNC: 40pts

NC State: 20pts

Mins: 10

UNC chance of winning: 98.82352941176471%

**Before submission, make sure that you do not have extra print statements other than the one(s) required (prompts and the print statement in 3.4c)! **

**Congrats! You are done with the last part of this problem set. All that there is left to do is publish your app and submit for grading (and test this out on a real basketball game!).**

**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**

**Grader coming soon!**

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!