JavaScript Learning Notes (iv) _JAVASCRIPT skills

Source: Internet
Author: User
Tags rounds square root
Local objects
①array class
②date class
object's type Built-in object
①global objects
②math objects
Host Object
Today continue to learn the object in JS, yesterday learned the two important objects in the local object array and date. Look at the built-in object global object and the Math object today.
Global Object
The encodeURI () method is used to process the complete URI, removing some whitespace and other characters.
The eval () method computes a string and executes the JavaScript code in it.
Math Object
The min () method and the Max () method are used to determine the maximum and minimum values in a set of numbers. Both of these methods can accept any number of parameters.
The Ceil () method represents a rounded up function that always rounds the number up to the nearest value.
The floor () method represents a downward rounding function that always rounds the number down to the nearest value.
The round () method represents the standard rounding function, rounded up if the difference between the number and the next integer is not more than 0.5, or rounded down. This is the rounding rule that was learned in junior high school.
The POW () method is used to raise a number to a specified power, such as to raise 2 to 10 powers (expressed in mathematics as 210).
The sqrt () method returns the square root of the specified number.
The Math object also has a complete trigonometric method.
The random () method returns a random number from 0 to 1, excluding 0 and 1. This is a common tool for sites that display random quotes or news on the home page.
Not finished ... Random () Method Example
Copy Code code as follows:

Returns the number of random numbers between two integers
function Randomfn (Strfirst, Strlast) {
var ifirst = parseint (Strfirst);
var ilast = parseint (strlast);
Number of two digits
var icount = Ilast-ifirst + 1;
if (icount > 0) {
The Randdom () function returns a random decimal number between 0 and 1.
var rannum = Math.floor (Math.random () * icount + Ifirst);//generally takes a random number in this format: times the total number, then adds the starting number, and finally rounds down
document.getElementById (' Label1 '). InnerHTML = Rannum;
}
else {
Alert ("Integer 2 should be larger than integer 1, please re-enter");
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.