Numbers Flashcards
What is one of the most common datatypes in JavaScript?
Strings
What are booleans?
True or false outcomes are booleans.
Can JavaScript numbers do simple and complex math?
Yes
It is possible to do simple + complex math with JS numbers.
How is math used in practical ways online?
Total Cost in online stores
Adding points in online games
Keeping track of metrics in web apps
What role do random numbers play?
Random numbers add variety and surprise to games.
Can numbers be positive or negative in JavaScript numbers?
Yes
Can you use decimals or only whole integers?
Both whole integers and decimals
How do you assign numbers?
You can store numbers in variables by using the equal sign.

Do numbers need special characters?
No, you don’t need quote marks.
If you add quote marks, it’s a string, not a number.
Can you use commas for longer numbers?
Ex: 1,456,789
No
You cannot use commas
Commas produces errors
What is the arithmetic operator for addition?
+
What is the arithmetic operator for subtraction?
-
What is the arithmetic operator for multiplication?
*
What is the arithmetic operator for division?
/
Can you combine variables with numbers as part of JavaScript arithmetic?
Yes
You can add variables with numbers.
Example: game scores

How do you write this in shorthand version?
score = score + 10;

Shorthand version of arithmetic simplifies
it by not having to write the variable name twice.
score += 10;

How do you flip the order of the signs in the shorthand version?
Put the operator before equal sign
+=
-=
*=
/=
For subtraction shorthand, how would you simplify the following code?

score -= 20;

For multiplication, how do you simplify it in shorthand?


For division, what’s the shorthand version?


To create a math program, you should start by

creating your variables and assigning values
Once you have your variables, how do you make your formula?

The formula itself goes into a new variable.
In this example, variables are multiplied by variables.
The solution is assigned to a new variable.

In this sales total example, what does it calculate?

The sales total is equal to quantity * retailPrice.
How would the profit be calculated using a new variable named const profit?


What happens if you treat numbers as strings?
The numbers are laid out next to each other, rather than following arithmetic rules.
Example 5+ 4 becomes 54, rather than 9.
What property helps you convert strings into numbers?
ParseInt()
What does ParseInt() do?
ParseInt() converts strings into integers
Can ParseInt() take positive/negative numbers?
Yes
Can you use decimals with ParseInt()?
No, whole numbers only can be used with ParseInt()
In what variable is ParseInt() used in this program?

const totalBadges
Why is ParseInt() useful?
What is a floating point number?
It’s a decimal number.
3.14
What does parseFloat() do?
It accepts decimal numbers for math formulas.
What does NaN stand for?
Not a number
It’s an error message
What are primative data types?
N.B.S.
N.B.S.
Numbers
Booleans
Strings
What does math.round do?
It rounds up to the next whole integer.
What result would this produce?

It would round to 2.
What number would this math.round example round to?

45
What are 2 reasons why would you want to
generate a random number?
Variety
Surprise
Random image
Random question
What property do you use to create random numbers?
Math.random
What does Math.floor do?
Math.floor rounds decimals down.
What does Math.ceil do?
Mail.ceil rounds decimals down.
For math.round, what logic does it use to round up or down?
If it is above .5, Math.round, rounds up.
If it is .4 or below, Math.round, rounds down.
Whats the lowest number that would be returned from this Math.random example?

1
What is the highest number it would return?

6
What range would this Math.random stay within?

1 and 6
It returns a value between 1 and 6.
When dealing with parenthesis, which runs first, inner or outer?

inner parenthesis runs first
Does Math.random() return whole numbers or decimals?
Typically it returns decimals
Even when multiplied against integers
Using const inputHigh, collect input from the user.
Collect the number using prompt method
Store the prompt in a variable

Use ParseInt to convert the input to a number
Using inputHigh to store highest number possible
Variable is constant
Variable name is highNumber
const highNumber = parseInt(inputHigh);

Use Math.random() and the user’s number to generate a random number
const is randomNumber
Math.floor to round down
use + 1 for a wider range

Create a message displaying the random number
Use console.log
Use string interpolation ${}
Use text for user
Use the range between 1 and high number

Check that the user provides a number using a conditional statement, highNumber variable, Math.floor, + 1. With 2 console.logs for the random number range and message to user.

How do you ask for a random number between two numbers?
Use const inputLow and inputHigh with prompts
Use the parseInt for both low and high number
Generate a random number with Math.floor
Create a formula with const randomNumber
Conditional statement
Print out to console.log the random number
Console.log to provide a two numbers, if needed
