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?

A
25
Q

What happens if you treat numbers as strings?

A

The numbers are laid out next to each other, rather than following arithmetic rules.

Example 5+ 4 becomes 54, rather than 9.

26
Q

What property helps you convert strings into numbers?

A

ParseInt()

27
Q

What does ParseInt() do?

A

ParseInt() converts strings into integers

28
Q

Can ParseInt() take positive/negative numbers?

A

Yes

29
Q

Can you use decimals with ParseInt()?

A

No, whole numbers only can be used with ParseInt()

30
Q

In what variable is ParseInt() used in this program?

A

const totalBadges

31
Q

Why is ParseInt() useful?

A
32
Q

What is a floating point number?

A

It’s a decimal number.

3.14

33
Q

What does parseFloat() do?

A

It accepts decimal numbers for math formulas.

34
Q

What does NaN stand for?

A

Not a number

It’s an error message

35
Q

What are primative data types?

N.B.S.

A

N.B.S.

Numbers

Booleans

Strings

36
Q

What does math.round do?

A

It rounds up to the next whole integer.

37
Q

What result would this produce?

A

It would round to 2.

38
Q

What number would this math.round example round to?

A

45

39
Q

What are 2 reasons why would you want to
generate a random number?

A

Variety

Surprise

Random image

Random question

40
Q

What property do you use to create random numbers?

A

Math.random

41
Q

What does Math.floor do?

A

Math.floor rounds decimals down.

42
Q

What does Math.ceil do?

A

Mail.ceil rounds decimals down.

43
Q

For math.round, what logic does it use to round up or down?

A

If it is above .5, Math.round, rounds up.

If it is .4 or below, Math.round, rounds down.

44
Q

Whats the lowest number that would be returned from this Math.random example?

A

1

45
Q

What is the highest number it would return?

A

6

46
Q

What range would this Math.random stay within?

A

1 and 6

It returns a value between 1 and 6.

47
Q

When dealing with parenthesis, which runs first, inner or outer?

A

inner parenthesis runs first

48
Q

Does Math.random() return whole numbers or decimals?

A

Typically it returns decimals

Even when multiplied against integers

49
Q

Using const inputHigh, collect input from the user.

Collect the number using prompt method

Store the prompt in a variable

A
50
Q

Use ParseInt to convert the input to a number

Using inputHigh to store highest number possible

Variable is constant

Variable name is highNumber

A

const highNumber = parseInt(inputHigh);

51
Q

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

A
52
Q

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

A
53
Q

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.

A
54
Q

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

A
55
Q
A