JavaScript learning note 017 - numeric method 0Math0 timer

Keywords: less encoding

Author: Mr. Liu Shangyuan

  • Give no less than any effort
  • May all our efforts be lived up to
  • Never forget why you started, and your mission can be accomplished.

I didn't miss you very deliberately
Because I know
We should be grateful when we meet
You need to let go when you pass by
I'm just in a lot of little moments
Think of you
Like a movie
A song
A Lyric
A road
and
Countless closed eyes moments
If I don't meet you
Will I have another life?
With or without results
I would rather meet you
Zhang Xiaoxian

<!DOCTYPE html> <!-- Document type: Standard html File -->

<html lang='en'> <!-- html Root tag translation text: English -->

<head> <!-- Webpage header -->

<meat charset='UTF-8'/> <!-- Web page character encoding -->

<meat name='Keywords' content='Keywords 1,Keywords 2'/>

<meat name='Description' content='Website description'/>

<meat name='Author' content='author'/>

<title>Front end 59 student assignments</title> <!-- Webpage title -->

<link rel='stylesheet' type='text/css' href='css/css1.css'/> <!-- Chain style sheet -->

<style type='text/css'> /*Internal style sheet*/

</style>

</head>

<body> <!-- Web backbone: visualization area -->

<script>
/*
Numerical method:
Number
*/
// es6 extension, judgment
Number.isFinite(9); // Determine whether the value is limited and return the Boolean value
Number.isNaN(papa); // Judge whether the value is a number and return a Boolean value
Number.isInteger(25.0); // Judge whether the value is an integer and return a Boolean value

// Number rounding, floating point
parseInt("12.34"); // 12 rounding
parseFloat("12.34aaa"); // 12.34 floating point number

/*
Math: 
Mathematical object
 Mostly mathematical
*/
// PI
Math.PI;

// Rounding up and down
let num = 1.2;
Math.ceil(num); // 2 round up
Math.floor(num); // 1 round down
Math.round(num); // 1 rounding

// Maximum, minimum
Math.max(1, 5, 3, 9, 7); // 9 return to maximum
Math.min(1, 5, 3, 9, 7); // 1 return to minimum

// Secondary power
Math.pow(10, 2); // 100 is equivalent to 10 * * 2
// Cube root
Math.cbrt(8); // 2
// Square root of sum of squares of all values
Math.hypot(3, 4); // 5
// es7 extension, exponential operator
10 ** 2; // 100;
b **= 3; // Equivalent to b = b * b * b

// Random value
Math.random( ); // [0, 1) the random value between 0 and 1 may be taken as 0, and will never be taken as 1
// Random value method
function fn(a, b){
return Math.floor(Math.random( ) * ((b + 1) - a) + a);
}
fn(1, 9);

// Decimals removed
Math.trunc(3.8); // 3

// Judge whether the value is positive, negative, zero
Math.sign(5); // +1 returns five values, positive (+ 1), negative (- 1), 0 (0), - 0 (- 0), other values (NaN)


/*
Timer:
One time timer
 Periodic timer
 Asynchronous operation
*/
// One time timer, one time execution is over
setTimeout(What to do (usually a function), Time interval (MS), Arguments to callback functions);

// Periodic timer, executed once in a while
setInterval(What to do (usually a function), Time interval (MS),  Arguments to callback functions);

// Clear timer
clearTimeout(The name of a timer or of a timer id); // Clear setTimeout
clearInterval(The name of a timer or its id); // Clear setInterval

// Example
let timer = setInterval(function (){
alert("Sting");
}, 500);
clearInterval(1); // Use the id value of timer to clear
clearInterval(a); // Use variable names to clear recommendations


</script>

</body>

</html>

Posted by Scifa on Tue, 31 Dec 2019 06:48:54 -0800