A Bookmarklet Calculator

If you think about it, it’s really a bit too difficult to do a full-fledged calculator with buttons and a running value on just one long line of code. However, you can use a bookmarklet like Script 17.11 to do fairly complex calculations, using JavaScript’s built-in Math functions, as described in Table 17.1.

Table 17.1. JavaScript’s Math Functionality
FunctionDescription
absAbsolute value
sin, cos, tanStandard trigonometric functions; arguments in radians
acos, asin, atanInverse trigonometric functions; return values in radians
exp, logExponential and natural logarithm, base e
ceilReturns least integer greater than or equal to argument
floorReturns greatest integer less than or equal to argument
minReturns lesser of two arguments ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.