math.js

math in Javascript
// finding absolute value of a number 
var number = -8;
let output = Math.abs(number);
console.log(output);

var num =6;
nums = Math.abs(num);
console.log(nums);

// finding ceil(khali upre di tanbo) of a number
var mynumber = 9.59;
let myceil = Math.ceil(mynumber);
console.log(myceil);

//  finding floor (kacher nichor shonka tanbo) of a number
var yournumber = 9.59;
let yourfloor = Math.floor(yournumber);
console.log(yourfloor);

// finding round of a number
var myround = 9.59;
let round = Math.round(myround)
console.log(round);

//finding a random number 
var outputs = Math.random()*8;
outputs = Math.floor(outputs)
console.log(outputs);

// making it on a for loop

for( let i=0; i<=20; i++){
    var outputs = Math.random()*8;
outputs = Math.floor(outputs)
console.log(outputs);
}
// github - redowanrafy707

4.43
7
Holloway 100 points

                                    function sum(a, b) {
  return a + b;
}

function subtract(a, b) {
  return a - b;
}

function multiply(a, b) {
  return a * b;
}

function divide(a, b) {
  if (b === 0) {
    console.log(&quot;can't divide by zero&quot;);
  }

  if (a === 0 &amp;&amp; b === 0) {
    console.log(&quot;undetermined&quot;);
  }

  //or this without any IFs
  return a / b;
}

4.43 (14 Votes)
0
4.22
9
DRY 85 points

                                    // functions and constants
math.round(math.e, 3)                // 2.718
math.atan2(3, -3) / math.pi          // 0.75
math.log(10000, 10)                  // 4
math.sqrt(-4)                        // 2i
math.derivative('x^2 + x', 'x')      // 2*x+1
math.pow([[-1, 2], [3, 1]], 2)
     // [[7, 0], [0, 7]]

// expressions
math.evaluate('1.2 * (2 + 4.5)')     // 7.8
math.evaluate('12.7 cm to inch')     // 5 inch
math.evaluate('sin(45 deg) ^ 2')     // 0.5
math.evaluate('9 / 3 + 2i')          // 3 + 2i
math.evaluate('det([-1, 2; 3, 1])')  // -7

// chaining
math.chain(3)
    .add(4)
    .multiply(2)
    .done() // 14

4.22 (9 Votes)
0
3.83
6
John Lapham 120 points

                                    JS Numbers and Math:

Number Properties:
MAX_VALUE
The maximum numeric value representable in JavaScript
MIN_VALUE
Smallest positive numeric value representable in JavaScript
NaN
The &ldquo;Not-a-Number&rdquo; value
NEGATIVE_INFINITY
The negative Infinity value
POSITIVE_INFINITY
Positive Infinity value

Number Methods:
toExponential()
Returns a string with a rounded number written as exponential notation
toFixed()
Returns the string of a number with a specified number of decimals
toPrecision()
String of a number written with a specified length
toString()
Returns a number as a string
valueOf()
Returns a number as a number

Math Properties:
E Euler&rsquo;s number
LN2 The natural logarithm of 2
LN10 Natural logarithm of 10
LOG2E Base 2 logarithm of E
LOG10E Base 10 logarithm of E
PI The number PI
SQRT1_2 Square root of 1/2
SQRT2 The square root of 2

Math Methods:
abs(x)
Returns the absolute (positive) value of x
acos(x)
The arccosine of x, in radians
asin(x)
Arcsine of x, in radians
atan(x)
The arctangent of x as a numeric value
atan2(y,x)
Arctangent of the quotient of its arguments
ceil(x)
Value of x rounded up to its nearest integer
cos(x)
The cosine of x (x is in radians)
exp(x)
Value of Ex
floor(x)
The value of x rounded down to its nearest integer
log(x)
The natural logarithm (base E) of x
max(x,y,z,...,n)
Returns the number with the highest value
min(x,y,z,...,n)
Same for the number with the lowest value
pow(x,y)
X to the power of y
random()
Returns a random number between 0 and 1
round(x)
The value of x rounded to its nearest integer
sin(x)
The sine of x (x is in radians)
sqrt(x)
Square root of x
tan(x)
The tangent of an angle

3.83 (6 Votes)
0
4
5
SYJ 75 points

                                    
Math.ceil(4.9);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// returns 5

Math.ceil(4.7);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// returns 5

Math.ceil(4.4);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// returns 5

Math.ceil(4.2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// returns 5

Math.ceil(-4.2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// returns -4

 

4 (5 Votes)
0
3.43
7
Sam 105 points

                                    //Math in JS is similar and different to the one in school
//Like: &quot;+&quot;, &quot;-&quot; signs are the same. But &quot;X&quot; and &quot;&divide;&quot; are replaced with &quot;*&quot; and &quot;/&quot; respectivly
//You can do math both with variables and normal numbers
________________________________________________________________________________
								Normal Number Examples
                                
4+4 = 8;
4-4 = 0;
4*4 = 16;
4/4 = 1;
________________________________________________________________________________
								Variable Examples
                                
num1 = 0;
num2 = 0;
ans = 0;

num1 = 4;
num2 = 64

num1 + num2 = 68
num1 - num2 = 60
num1 * num2 = 24
num1 / num2 = 256;

num1 + num2 = ans;
num1 - num2 = ans;
num1 * num2 = ans;
num1 / num2 = ans;
________________________________________________________________________________
Now, you can use the document.getElementByID(&quot;&quot;).innerHTML = ans; to set the answer



//I hope this post helped you!

3.43 (7 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
maths for js math for js math javascript w3s Math js javascript math % w3schools math javascript math javascript w3schools math function with javascript javascript matho javascript math mathematics example math functions in js javascript math w3schools math in javascrip how to do basic math in html and javascript javascript math operators math function js examples math in js w3sch Math javacsript js math fu js math function math method js maths methods in javascript javascript math w3 Math object in Javascript ^ math in js how to use math functions in js math expressions js js Math.i java script math math javaascript math ja math. functions in javascript Math + js math. in javascript how to use math methods in jS function that does math js math.js javascript how to use MATH in js .math in javascirpt javascript.math how to do math in javascript math in javascript use math functions in javascript math de javascript what is Math in Javascript what is math function in javascript basic math functions javascript how to code in js math simple math in js Math. in js how does math work in js math en javascript math used js js math object math js functions javascripy math math injavascript jacascript math mathematics javascript math operation js how to use math function in javascript javscript math. methods math javascript math.in js math function to javascript maths with javascript javascript mathes function % javascript math using math methods in javascript javscript math math metohds in js math function in javascrript math() js math math math how to do math in js math .js math . javascript math , math operations js js math mas js math func math method in javascript javascript maths functions math js math.() js math ^ js math() basic maths in javascript Math jaascript how to use math in javascript (.) math maths in js what is math javascript js mathpow math functions in javascript how to use math.js using math in javascript how to use math js html math js math js how to use use math in javascript math in javascript number Math functions js method math js what is math in javascriopt maths in javascript math function js javascript math example javascript math functions example javascript math operations javascript math math operations javascript math in js basic math javascript js Math. math javascript math js math operations math for javascript math.math javascript math object maths method javascript math method math methods in javascript math methods in js math methods js use of math in javascript javascript math with ^ javascript math ~ javascript | math Math methodos javascript javascript mathods % js math math javascript functions math. Math operations in js math javscript do math in js how to define math in javascript maths js math function in js math functions in javascript maths function in js javascrpit math math in js js math methods what is Math in js how to do math javascript javascrip math math function in javascript math js methods math.in javascript math with java script math method javascript class math javascript mathematical js libraries js math module -= math js js % math method in a method javascript using math typescript math library math methods javascript maths javascript js ln math math ! math functions javascript js math functions math method in js javascript math class how to do maths in node javascript math funcions default math javascript math.js node.js how to import math in javascript discrete math in javascript javascript math module vue math.js math library in javascript javascript math functions js maths objects javascript mat javascript maths javascript math methods javascript math objects wr3 all math methos js javascript math&ugrave; js maths math js inaccurate math js docs python mathsjs javascript advanced math best javascript math library mathjs projects math library js javascript import math mathml js math function javascript javascript math function math in javascript how to do math node js .Math javascript javascript math npm calculus library js calculus library Math i nodejs mathematical javascript library math javascript math. javascript javascript math. Math documentation javavscript quick math js math() javascript amth js math.js tutorial math library in js math node js mathjs testing maht js js math library math in nodejs math calculus javascript math and js jqmath librar javascript math libraries js Mathc labrary math. js Maths.js msth js calc math js math libraries js ^ math js math math js math nodejs 1+1 where to get math library for javascript amath. js javascript math.js javascript lib percect math react math library what does math js do math-utils library javascript math javascript library js math math package in js program mathematical algorithm js program mathematic algorithm js javascript library for mathematics javascript math library maths engine javascript mathjs jquery plugin Easy JS algorithms using Math math lib js math library javascript inbuilt math library in javascript math library in react js math library in react mathjs Math.js math js library math js
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source