Today, we are starting our journey into JavaScript. For this assignment, you
will be making a program that demonstrates some JavaScript fundamentals.
Objectives
Ensure your development environment is setup
Practice creating variables
Practice working with user input
Requirements
Create your project using app-app with the beta stack
Remove all the code inside main.js and start with a fresh and empty file.
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 (even if that is zero).
Create a variable called fullName and set it equal to your full name.
Use console.log and your variables, numberOfCupsOfCoffee and fullName to output all three on one line.
Practice Getting Input From the User
Ask the user for their name and store it in a variable named userName. (use window.prompt to get input from the user)
Console log a greeting to the user, using their name.
Converting String Input Into Numbers
Input two numbers from the user. Use window.prompt twice, once for each prompt/number. Convert each resulting string from window.prompt to a float using parseFloat. Save the first value in a variable named firstOperand and the second value in a variable named secondOperand.
Doing Math
Add the operand variables from above and save the results in a variable named sum.
Subtract the secondOperand variable from the firstOperand variable and
save the results in a variable named difference.
Multiply the operand variables and save the results in a variable named
product.
Divide the firstOperand by the secondOperand and save the results in a
variable named quotient.
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 the sum, difference, quotient, product, and remainder variables. (e.g. perhaps one of your outputs is similar to
If you add 4 and 5 you get 9 if 4 and 5 were the input)
Using Arrays
Use
this page to generate a array of random numbers.
Place these numbers into a properly formatted array named numbers.
Determine the following. Use JavaScripts for loops to your advantage.
In a variable named smallest, find the smallest value in the array
In a variable named largest, find the largest value in the array
In a variable named sum, find the sum of all the values in the array
In a variable named average, find the average of all the values in the
array
Adventure Mode
Revisit your arrays. This time create new variables that represent:
sumOfOdd that contains the sum of all the odd numbers
countOfEven that contains the total count of all the even numbers
Let's get started
Today, we are starting our journey into JavaScript. For this assignment, you will be making a program that demonstrates some JavaScript fundamentals.
Objectives
Requirements
Create your project using
app-app
with thebeta
stackRemove all the code inside
main.js
and start with a fresh and empty file.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 (even if that is zero).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.Practice Getting Input From the User
Ask the user for their name and store it in a variable named
userName
. (usewindow.prompt
to get input from the user)Console log a greeting to the user, using their name.
Converting String Input Into Numbers
Input two numbers from the user. Use
window.prompt
twice, once for each prompt/number. Convert each resultingstring
fromwindow.prompt
to afloat
using parseFloat. Save the first value in a variable namedfirstOperand
and the second value in a variable namedsecondOperand
.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)Using Arrays
Use this page to generate a array of random numbers.
Place these numbers into a properly formatted array named
numbers
.Determine the following. Use JavaScripts
for
loops to your advantage.smallest
, find the smallest value in the arraylargest
, find the largest value in the arraysum
, find the sum of all the values in the arrayaverage
, find the average of all the values in the arrayAdventure Mode
sumOfOdd
that contains the sum of all the odd numberscountOfEven
that contains the total count of all the even numbers