Beginner JavaScript Tutorial – 36 – Math Objects

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

29 responses to “Beginner JavaScript Tutorial – 36 – Math Objects”

  1. Escape the Matrix Avatar

    Bucky is a fart smeller. Oops, I meant smart feller.

  2. #MandariGlenn Avatar

    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

  3. Nitin Sharma Avatar

    I m so glad i found this channel. Otherwise i'd have failed. Thanks bucky

  4. Warren Crasta Avatar

    Just FYI: Euler is pronounced "oiler" 🙂

  5. Robson Sousa Avatar

    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>

  6. Dan Varlan Avatar

    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"

  7. Mervin Lee Avatar

    how come we don't need to use return answer here? because I thought that you need to use return when using any math's calculation. If not, then when would we use return? thanks!

  8. Benjamin steffen Avatar

    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", "")));

  9. allwyn mathias Avatar

    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>

  10. Georgi Georgiev Avatar

    Thank you very much.
    GOD bless you, Bucky.

  11. Zhenhao Zhou Avatar

    why do you put a coma in the prompt statement? can't you just do prompt("Enter a number");?

  12. le900 Avatar

    What about Math.random(): ?

  13. Michael Miller Avatar

    Aren't these actually Math.properties?

    Because Math = object and . defines it's properties.

  14. Roger kun Avatar

    nice comment… and picture.

  15. rawnok ashraf Avatar

    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.

  16. Jerry Remig Avatar

    who liked because of the photo

  17. Kevin Perkins Avatar

    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. 😉

  18. Aaron D'Souza Avatar

    Can't take you seriously with dat pic 😛

  19. Spencer Avatar

    and 10 trillionth digit is 5 😀
    YAY Internet!

  20. Dhruv Kumar Avatar

    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

  21. RLS0812 Avatar

    3:45 Can't you just use "**0.5" instead of "Math.sqrt()" ?

  22. Michael1773196 Avatar

    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.

  23. xxiRaQiAtheistxx Avatar

    let me guess!

    1..Its your ass
    2..your sister's ass
    3..your sweet mother's ass..
    I knew it i was correct 😉
    Also, thankkkkkkkkkkkkkkkks BuCKy!

Leave a Reply

Your email address will not be published. Required fields are marked *