Numbers Flashcards

1
Q

What is one of the most common datatypes in JavaScript?

A

Strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are booleans?

A

True or false outcomes are booleans.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can JavaScript numbers do simple and complex math?

A

Yes

It is possible to do simple + complex math with JS numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How is math used in practical ways online?

A

Total Cost in online stores

Adding points in online games

Keeping track of metrics in web apps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What role do random numbers play?

A

Random numbers add variety and surprise to games.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can numbers be positive or negative in JavaScript numbers?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can you use decimals or only whole integers?

A

Both whole integers and decimals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you assign numbers?

A

You can store numbers in variables by using the equal sign.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Do numbers need special characters?

A

No, you don’t need quote marks.

If you add quote marks, it’s a string, not a number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Can you use commas for longer numbers?

Ex: 1,456,789

A

No

You cannot use commas

Commas produces errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the arithmetic operator for addition?

A

+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the arithmetic operator for subtraction?

A

-

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the arithmetic operator for multiplication?

A

*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the arithmetic operator for division?

A

/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Can you combine variables with numbers as part of JavaScript arithmetic?

A

Yes

You can add variables with numbers.

Example: game scores

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you write this in shorthand version?

score = score + 10;

A

Shorthand version of arithmetic simplifies
it by not having to write the variable name twice.

score += 10;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you flip the order of the signs in the shorthand version?

A

Put the operator before equal sign

+=

-=

*=

/=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

For subtraction shorthand, how would you simplify the following code?

A

score -= 20;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

For multiplication, how do you simplify it in shorthand?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

For division, what’s the shorthand version?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

To create a math program, you should start by

A

creating your variables and assigning values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Once you have your variables, how do you make your formula?

A

The formula itself goes into a new variable.

In this example, variables are multiplied by variables.

The solution is assigned to a new variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

In this sales total example, what does it calculate?

A

The sales total is equal to quantity * retailPrice.

24
Q

How would the profit be calculated using a new variable named const profit?

25
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.
26
What property helps you convert strings into numbers?
ParseInt()
27
What does ParseInt() do?
ParseInt() converts strings into integers
28
Can ParseInt() take positive/negative numbers?
Yes
29
Can you use decimals with ParseInt()?
No, whole numbers only can be used with ParseInt()
30
In what variable is ParseInt() used in this program?
const totalBadges
31
Why is ParseInt() useful?
32
What is a floating point number?
It's a decimal number. 3.14
33
What does parseFloat() do?
It accepts decimal numbers for math formulas.
34
What does NaN stand for?
**Not a number** It's an error message
35
What are primative data types? N.B.S.
**N.B.S.** Numbers Booleans Strings
36
What does math.round do?
It rounds up to the next whole integer.
37
What result would this produce?
It would round to 2.
38
What number would this math.round example round to?
45
39
What are 2 reasons why would you want to generate a random number?
Variety Surprise Random image Random question
40
What property do you use to create random numbers?
**Math.random**
41
What does Math.floor do?
Math.floor rounds decimals down.
42
What does Math.ceil do?
Mail.ceil rounds decimals down.
43
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.
44
Whats the lowest number that would be returned from this Math.random example?
1
45
What is the highest number it would return?
6
46
What range would this Math.random stay within?
1 and 6 It returns a value between 1 and 6.
47
When dealing with parenthesis, which runs first, inner or outer?
inner parenthesis runs first
48
Does Math.random() return whole numbers or decimals?
Typically it returns decimals Even when multiplied against integers
49
Using const inputHigh, collect input from the user. Collect the number using prompt method Store the prompt in a variable
50
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);
51
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
52
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
53
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.
54
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
55