Section 12: Numbers, Dates, Intl and Timers Flashcards

1
Q
  1. How to extract number parts from a string?
    *
    *
    *
    *
  2. Get result of
    “console.log(Number.parseInt(‘23px’));
    console.log(Number.parseInt(‘px23’));
    console.log(Number.parseInt(‘ 2.5rem ‘));
    console.log(Number.parseFloat(‘ 2.5rem ‘));
    console.log(parseFloat(‘ 2.5rem’));
A
console.log(Number.parseInt('23px')); // 23
console.log(Number.parseInt('px23')); // NaN

console.log(Number.parseInt('   2.5rem   ')); // 2
console.log(Number.parseFloat('  2.5rem   ')); // 2.5

console.log(parseFloat(' 2.5rem')); // 2.5"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Problem

Create a function(min number, max number). Generate random number

A

“const randomInt = (min, max) =>
Math.floor(Math.random() * (max - min + 1)) + min;”

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

Definition

  1. How many way to round integer number?
  2. How many way to round decimal number? Problem? How to fix?
A
  1. + Math.trunc(): Cut decimal part
    + Math.round(): Round to nearest number
    + Math.ceil(): Round up
    + Math.floor(): Round down
  2. toFixed(). Convert result to string. Use “+” to convert back to number
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Problem

Get result of
“console.log(Math.trunc(23.3));

console.log(Math.round(1.2)); //
console.log(Math.round(1.5)); //
console.log(Math.round(1.6)); //
console.log(Math.round(-1.1)); //
console.log(Math.round(-1.5)); //
console.log(Math.round(-1.6)); //

console.log(Math.ceil(1.2)); //
console.log(Math.ceil(1.5)); //
console.log(Math.ceil(1.6)); //
console.log(Math.ceil(-1.1)); //
console.log(Math.ceil(-1.5)); //
console.log(Math.ceil(-1.6)); //

console.log(Math.floor(1.2)); //
console.log(Math.floor(1.5)); //
console.log(Math.floor(1.6)); //
console.log(Math.floor(-1.1)); //
console.log(Math.floor(-1.5)); //
console.log(Math.floor(-1.6)); //

A
"console.log(Math.trunc(23.3));

console.log(Math.round(1.2)); // 1
console.log(Math.round(1.5)); // 2
console.log(Math.round(1.6)); // 2
console.log(Math.round(-1.1)); // -1
console.log(Math.round(-1.5)); // -1
console.log(Math.round(-1.6)); // -2

console.log(Math.ceil(1.2)); // 2
console.log(Math.ceil(1.5)); // 2
console.log(Math.ceil(1.6)); // 2
console.log(Math.ceil(-1.1)); // -1
console.log(Math.ceil(-1.5)); // -1
console.log(Math.ceil(-1.6)); // -1

console.log(Math.floor(1.2)); // 1
console.log(Math.floor(1.5)); // 1
console.log(Math.floor(1.6)); // 1
console.log(Math.floor(-1.1)); // -2
console.log(Math.floor(-1.5)); // -2
console.log(Math.floor(-1.6)); // -2"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Problem

“Problem: Round the requested loan amount
- Round down load amount
- Other amount should have 2 decimal part after “.”
- 
https://codepen.io/luckily1702/pen/BavxZoV”

“Hint

- When enter request loan, automatically round down (Ex: 300.45 => 300)

- Display 2 decimal parts in 3 places: Current balance, display movements, Summary (In, out, interest) “

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

Problem

”/* write a isEven function
- Take a number as argument
- Return true if number is even
*/”

A

“const isEven = number => number % 2 === 0;

console.log(isEven(3)); // false
console.log(isEven(6)); // true
console.log(isEven(9)); // false”

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

Problem

/*
In ‘Bankist App’. When login, user click on label summary amount and obser color change in movements row
- Color in every second movements row in browser to orangered; (line 0,2,4,6,…)
- Color in every third movements row in browser to blue; (line 0,3,6,9)

https://codepen.io/luckily1702/pen/BavxZoV
*/

A

“labelBalance.addEventListener(‘click’, function () {
[…document.querySelectorAll(‘.movements__row’)].forEach((el, i) => {
if (i % 2 === 0) el.style.backgroundColor = ‘orangered ‘;
if (i % 3 === 0) el.style.backgroundColor = ‘blue ‘;
});
});”

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

Definition

  1. How to work with big number? What is that data type?
  2. How many way to display correct big number?
A
  1. bigint
  2. + use “n” at the end of number
    + use BigInt( ) (only work with smaller big number than “n” )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly