Working With Numbers Flashcards

1
Q

What is a floating point number?

A

3.14

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

What is an example of a number using scientific notation?

A

9e-6

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

What is an example of an integer?

A

127 and -112345

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

What stores the number 225,622 in the variablemilesToTheMoon?

A

var milesToTheMoon = 225622;

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

Given the following code:

var userAge = ‘32’;

What type of value is stored in the variable userAge?

A

string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • Create a variable named age and store your age in the variable.
  • Add a second variable named price and store a floating point value (a number with a decimal) in it.
A
var age = 26;
var price = 0.99;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What adds 20 to the current value of the variable points, then stores the result back into points.

A

points += 20

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  • Create a new variable salesTotal that contains the total of the retailPrice multiplied by thequantity variable.

var wholesalePrice = 5.45;

var retailPrice = 9.99;

var quantity = 47;

  • Create another variable named profit. It should hold the value of the salesTotal variable minus the wholesalePrice multiplied by the quantity. In other words, if you sold 47 items for 9.99 but only paid 5.45 for each item, how much money did you make?
  • Create one last variable name profitPerUnit. In that variable store the amount of profit you made for each unit. You can calculate this by dividing the profit by the quantity.
A

var salesTotal = retailPrice * quantity;

var profit = salesTotal - wholesalePrice * quantity;

var profitPerUnit = profit / quantity

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

Let’s assume we have 10

tags on a page. Each is 190 pixels wide. Using the two variables in this script, create a new variable named totalWidth that multiples the width by the numOfDivsvariable. You’ll need to use a JavaScript function to retrieve the number value from the string in the width variable.

var width = '190px';
var numOfDivs = 10;
A

var totalWidth = parseInt(width) * numOfDivs

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

What will appear in the JavaScript console after this code runs?

console.log( parseInt( ‘.5 FTE’ ));

A

NaN

  • Because the first character is a . (decimal point) the parseInt() method sees this as a string, not a number.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What will appear in the JavaScript console after this code runs?

console.log( Math.round( 3.9 ) );

A

4

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

What will appear in the JavaScript console after this code runs?

console.log( parseInt( ‘7 days a week’ ) );

A

7

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

What JavaScript method takes a string and tries to convert it to an integer (a whole number)?

A

parseInt()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  • For this Code Challenge you need to use JavaScript’s Math methods. Open an alert dialog and display the temperature variable rounded to the nearest integer.

var temperature = 37.5

  • Open an alert dialog a second time and display the temperature variable rounded downward to the nearest integer (hint: down is toward the “floor”.)
A

alert(Math.round(temperature));

alert(Math.floor(temperature));

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

What code produces a random number from 1 to 6 and stores it inside a variable named dieRoll?

A

var dieRoll = Math.floor( Math.random() * 6 ) + 1;

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

What will appear in the JavaScript console after this code runs?

console.log( parseFloat( ‘.5 hours’ ));

A

0.5

17
Q

Complete the following code so that the results of this math operation are rounded down to the nearest integer. For example, .6 will be rounded to 0.

Math._____( 5 / 2)

A

floor

18
Q

What code snippets divides the value inside the pizza variable by 8 and stores the result back into pizza?

A
  • pizza = pizza / 8
  • pizza /= 8
19
Q

What does Math.random() do?

A

It produces a random number from 0 up to and but not including 1. For example, it could return 0, 0.3898784155026078 but never 1.