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
numberOfCupsOfCoffee
that you drink every day. - Create a variable called
fullName
and set it equal to your full name. - Use
console.log
and your variables,numberOfCupsOfCoffee
andfullName
to output all three on one line. - Create an variable that stores an object. Make the properties of the object
fullName
,luckyNumber
, andfavoriteMovies
. Wherefullname
is your full name,luckyNumber
is a number value of your favorite number, andfavoriteMovies
is 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.log
to show a greeting to the user, using their name.
- Using
Converting String Input Into Numbers
- Input two numbers from the user. Convert each resulting
string
fromwindow.prompt
to anumber
using Number. Save the first value in a variable namedfirstOperand
and 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
secondOperand
variable from thefirstOperand
variable and save the results in a variable nameddifference
. - Multiply the operand variables and save the results in a variable named
product
. - Divide the
firstOperand
by thesecondOperand
and 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.log
to present the user, in a meaningful way, each of the values for thesum
,difference
,quotient
,product
, andremainder
variables. (e.g. perhaps one of your outputs is similar toIf you add 4 and 5 you get 9
if4
and5
were 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
for
loops:- 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
stats
with 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:
sumOfOdd
that contains the sum of all the odd numberscountOfEven
that contains the total count of all the even numbers