1<!DOCTYPE html>
2<html>
3<body>
4
5<h2>JavaScript Functions</h2>
6
7<p>calculator function example</p>
8
9<label>Result:</label>
10
11<p id="fnc"></p>
12
13<script>
14function myFunction(p1, p2) {
15 return p1 * p2;
16}
17document.getElementById("fnc").innerHTML = myFunction(2, 3);
18</script>
19
20</body>
21</html>
22
1function myFunction(var1, var2) {
2 return var1 * var2;
3}
43
5How to create a function in javascriptJavascript By TechWhizKid on Apr 5 2020
6function addfunc(a, b) {
7 return a + b;
8 // standard long function
9}
10
11addfunc = (a, b) => { return a + b; }
12// cleaner faster way creating functions!
1var pi = Math.PI; // 3.141592653589793
2Math.round(4.4); // = 4 - rounded
3Math.round(4.5); // = 5
4Math.pow(2,8); // = 256 - 2 to the power of 8
5Math.sqrt(49); // = 7 - square root
6Math.abs(-3.14); // = 3.14 - absolute, positive value
7Math.ceil(3.14); // = 4 - rounded up
8Math.floor(3.99); // = 3 - rounded down
9Math.sin(0); // = 0 - sine
10Math.cos(Math.PI); // OTHERS: tan,atan,asin,acos,
11Math.min(0, 3, -2, 2); // = -2 - the lowest value
12Math.max(0, 3, -2, 2); // = 3 - the highest value
13Math.log(1); // = 0 natural logarithm
14Math.exp(1); // = 2.7182pow(E,x)
15Math.random(); // random number between 0 and 1
16Math.floor(Math.random() * 5) + 1; // random integer, from 1 to 5
17