Number 3/3
Other Math Functions
JavaScript has a library by the name of Math that has many built-in mathematics functions and methods. Let’s look at a few of them.
Math.random():
TheMath.random()is a function in JavaScript, that gives random numbers between0and1but not including1, for example.
123console.log(Math.random()); console.log(Math.random()); console.log(Math.random());
As you can see we get three different numbers between 0 and 1.
Note:
You may get different output as Math.random() gives random numbers.
Math.max()andMath.min():
TheMath.max()returns the greatest number of all the numbers passed in as an argument whileMath.min()returns the smallest one.
12console.log(Math.max(3, 5, -10, 100, 1)); console.log(Math.min(1, 2, 6, 0, -15));
Math.pow(base, power):
TheMath.pow(base, power)returnsbaseraised to the givenpower, for example.
1console.log(Math.pow(2, 10));
Swipe to start coding
The task is to find the volume of a cylinder. The radius and height variables are given to storing the radius and the height of the cylinder. The formula for the volume of the cylinder is:
V = πhr²
where π is the Math PI having the value of 3.1415, r is the radius, and h is the height. Your task is to create a new const variable named PI and store 3.1415 in it and implement this formula storing the result in a variable named volume.
Рішення
Summary
- JavaScript provides the facility of rounding numbers.
- We can check whether a variable is finite or infinite through the
isFinite()function. - We can check whether a variable is a number or not through the
isNaN()function. - The
Math.random()function is used to get a random numeric value from0to1(excluding1).
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 2
Number 3/3
Свайпніть щоб показати меню
Other Math Functions
JavaScript has a library by the name of Math that has many built-in mathematics functions and methods. Let’s look at a few of them.
Math.random():
TheMath.random()is a function in JavaScript, that gives random numbers between0and1but not including1, for example.
123console.log(Math.random()); console.log(Math.random()); console.log(Math.random());
As you can see we get three different numbers between 0 and 1.
Note:
You may get different output as Math.random() gives random numbers.
Math.max()andMath.min():
TheMath.max()returns the greatest number of all the numbers passed in as an argument whileMath.min()returns the smallest one.
12console.log(Math.max(3, 5, -10, 100, 1)); console.log(Math.min(1, 2, 6, 0, -15));
Math.pow(base, power):
TheMath.pow(base, power)returnsbaseraised to the givenpower, for example.
1console.log(Math.pow(2, 10));
Swipe to start coding
The task is to find the volume of a cylinder. The radius and height variables are given to storing the radius and the height of the cylinder. The formula for the volume of the cylinder is:
V = πhr²
where π is the Math PI having the value of 3.1415, r is the radius, and h is the height. Your task is to create a new const variable named PI and store 3.1415 in it and implement this formula storing the result in a variable named volume.
Рішення
Summary
- JavaScript provides the facility of rounding numbers.
- We can check whether a variable is finite or infinite through the
isFinite()function. - We can check whether a variable is a number or not through the
isNaN()function. - The
Math.random()function is used to get a random numeric value from0to1(excluding1).
Дякуємо за ваш відгук!
single