Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts
Original source
33 responses to “Beginner JavaScript Tutorial – 36 – Math Objects”
i love you ……man!!!!! you are great ……stay blessed always
Just say "squirt" instead of sqrt.
Can this be used with html5 or should I switch to xhtml strict to follow?
Very helpful. You have a real gift for teaching. Very valuable to we who are just learning JS. Thanks!
This bucky guy knows a lot of stuff,he is awesome
Yadiyadiyada
Euler Number btw, not Euler constant. 2 different numbers, but anyway – great tutorial;-)
Bucky is a fart smeller. Oops, I meant smart feller.
Question, why do I have to write the word new when doing:
var VARNAMEHERE = NEW Array();
but don't have to write it when I'm doing:
var VARNAMEHERE = prompt();
what does the word new do?
thank you
I m so glad i found this channel. Otherwise i'd have failed. Thanks bucky
i hate math 🙁
Just FYI: Euler is pronounced "oiler" 🙂
Thanks again Bucky! I m learning and test another methods of Math… like these…
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Beginner Javascript Tutorial</title>
<!– Beginner JavaScript Tutorial – 36 – Math Objects –>
</head>
<body>
<script type="text/javascript">
// document.write(Math.PI, "<br/>");
// You may test the another methods behavior from MATH class. For example…
// Remember to test diferents values like floats between "0.1, 0.2 + … + 0.9", floats ..1.4+… +4.5…
var pi = Math.PI;
var e = Math.E;
document.write(pi, "<br/>");
document.write(e, "<br/>");
var n = prompt("Enter a number", "");
var answerA = Math.sqrt(n);
var answerB = Math.pow(2, n);
var answerC = Math.abs(n);
var answerD = Math.acos(n);
var answerE = Math.asin(n);
var answerF = Math.atan(n);
var answerG = Math.ceil(n);
var answerH = Math.cos(n);
var answerI = Math.exp(n);
var answerJ = Math.round(n);
var answerK = Math.sin(n);
var answerL = Math.tan(n);
a = "The square root of " + n + " is " + answerA;
b = "The base 2 exponent by " + n + " is " + answerB;
c = "Return the absolute value of " + n + " is " + answerC;
d = "Return the arccosine of n, in radians " + n + " is " + answerD;
e = "Return the arcsine of n, in radians " + n + " is " + answerE;
f = "Return the arctangent of n as a numeric value between -PI/2 and PI/2 radians " + n + " is " + answerF;
g = "Return of n, rounded upwards to the nearest integer " + n + " is " + answerG;
h = "Return the cosine of n (n is in radians) " + n + " is " + answerH;
i = "Return the value of E^n " + n + " is " + answerI, "<br/>"
j = "Return n, rounded downwards to the nearest integer " + n + " is " + answerJ;
k = "Return the sine of n (n is in radians) " + n + " is " + answerK;
l = "Return the tangent of an angle" + n + " is " + answerL;
alert(a);
alert(b);
alert(c);
alert(d);
alert(e);
alert(f);
alert(g);
alert(h);
alert(i);
alert(j);
alert(k);
alert(l);
document.write(a + "<br>");
document.write(b + "<br>" );
document.write(c + "<br>" );
document.write(d + "<br>" );
document.write(e + "<br>" );
document.write(f + "<br>" );
// or printing using the method write one time only
document.write(g + "<br>", h + "<br>", i + "<br>", j + "<br>", k + "<br>", l + "<br>" );
</script>
</body>
</html>
If anyone is wandering…. If you put letters insted of numbers , it will tell you :
"The square root of (whatever you put in) is NaN"
NaN means "Not a Number"
its alot easier to write
var x = (Math.sqrt(prompt("Enter a number", "")));
alert("The square root of " + x*x + " is " + x);
even shorter:
alert(Math.sqrt(prompt("Enter a number", "")));
Math.PIE
Can anyone figure why in the following code only the 1st document.write is executed but not the second ?
<!DOCTYPE html>
<html>
<head></head>
<body>
<script type="text/javascript">
document.write(Math.PI);
var num = prompt("Enter a number:", "");
var answer = Math.sqrt(num);
document.write(answer);
</script>
</body>
</html>
Thank you very much.
GOD bless you, Bucky.
w3schools.com!!!
why do you put a coma in the prompt statement? can't you just do prompt("Enter a number");?
What about Math.random(): ?
4 more
Aren't these actually Math.properties?
Because Math = object and . defines it's properties.
nice comment… and picture.
No, it's 5…
Hey Bucky…when you used prompt like this:
var n= prompt("enter your number"," ");
…it means user is giving a String as input in the prompt box,right? so how a string can be used as a number? is it converting from string to integer automatically? i understand the fact,but i just wanna make sure.
btw…huge fan of yours.
thanks.
who liked because of the photo
Well Bucky, I'm still here, if I have trouble remembering all this, one thing I'll always remember, is how You can remember PI to so many places!
PI will never be the same again, doesn't bare thinking about. 😉
Can't take you seriously with dat pic 😛
because Math.sqrt() is an inbuilt function. It was created by the developers of JavaScript and you dont have to re-write the Math.sqrt() function in your program again. It already exists and is ready to use. hope this was helpful
3:45 Can't you just use "**0.5" instead of "Math.sqrt()" ?
That would be cool, so he could kinda go over a practical use of the programming. I would really look forward to that, it would also be very helpful.
DAT ass