Variables, Variables, and Variables
Let's get started
Today, we are starting our journey into TypeScript. For this assignment, you will be making a program that demonstrates some TypeScript fundamentals.
Objectives
- Ensure your development environment is setup
- Practice creating variables
- Practice working with user input
Setup
degit $GITHUB_USER/html-css-ts-project-template VariablesJS
Explorer Mode
Create a new app that does the following.
Practice Creating Variables
- Create a variable that stores the
numberOfCupsOfCoffeethat you drink every day. - Create a variable called
fullNameand set it equal to your full name. - Use
console.logand your variables,numberOfCupsOfCoffeeandfullNameto output all three on one line. - Create an variable that stores an object. Make the properties of the object
fullName,luckyNumber, andfavoriteMovies. Wherefullnameis your full name,luckyNumberis a number value of your favorite number, andfavoriteMoviesis an array of strings of a few of your top movies. NOTE: Try doing this using object literal:const aboutMe = { }and put the properties inside.
- Create a variable that stores the
Practice Getting Input From the User
- Using
window.prompt, Ask the user for their name and store it in a variable nameduserName. - Use
console.logto show a greeting to the user, using their name.
- Using
Converting String Input Into Numbers
- Input two numbers from the user. Convert each resulting
stringfromwindow.promptto anumberusing Number. Save the first value in a variable namedfirstOperandand the second value in a variable namedsecondOperand.
- Input two numbers from the user. Convert each resulting
Doing Math
- Add the operand variables from above and save the results in a variable named
sum. - Subtract the
secondOperandvariable from thefirstOperandvariable and save the results in a variable nameddifference. - Multiply the operand variables and save the results in a variable named
product. - Divide the
firstOperandby thesecondOperandand save the results in a variable namedquotient. - Find the remainder when one operand is divided by the other and save the results in a variable named
remainder. - Use
console.logto present the user, in a meaningful way, each of the values for thesum,difference,quotient,product, andremaindervariables. (e.g. perhaps one of your outputs is similar toIf you add 4 and 5 you get 9if4and5were the input)
- Add the operand variables from above and save the results in a variable named
Using Arrays
Use this page to generate an array of random numbers. NOTE: That format isn't ready for TypeScript. In your editor, you will need to format the collection of numbers as a TypeScript array.
Place these numbers into a properly formatted array named
numbers.Determine the following using one (or more) TypeScript
forloops:- Find the smallest number in the array and place the answer in a variable named
smallest - Find the largest number in the array and place the answer in a variable named
largest - Find the sum of all the numbers in the array and place the answer in a variable named
arraySum - Find the average of all the numbers in the array and place the answer in a variable named
average
- Find the smallest number in the array and place the answer in a variable named
Create an object called
statswith the following properties- In a property named
smallest, put the value of the variablesmallest - In a property named
largest, put the value of the variablelargest - In a property named
sum, put the value of the variablearraySum - In a property named
average, put the value of the variableaverage
- In a property named
Adventure Mode
- Revisit your arrays. This time create new variables that represent:
sumOfOddthat contains the sum of all the odd numberscountOfEventhat contains the total count of all the even numbers