Math.js is not working on jsfiddle

811 views Asked by At

I'm new to jsfiddle so it's probably something obvious but I cannot get the CDN for Math.js to work.

Here is my html code

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/1.6.0/math.js"></script>

and here is my javascript

alert(Math.sqrt(-4));

When I run the code it gives me NaN which is what it should give if Math.js has not loaded because Math.js is supposed to support imaginary numbers. Any help is appreciated

Here's the URL for the fiddle: https://jsfiddle.net/noahthefuzzy/95mxb0dL/2/

And here is the website for Math.js

2

There are 2 answers

0
Jos de Jong On BEST ANSWER

You should use lowercase math instead of uppercase Math:

alert(math.sqrt(-4)); // 2i
1
Scott Cowan On

Actually, Math.sqrt() returns NaN for negative values. Change your javascript to,

alert(Math.sqrt(4));

And you'll see Math.js is loading fine.