2009-06-04

Console: A simple Calculator

Upcoming v3.6 includes a new JavaScript Expression evaluator.

How To

  1. Open the Console (Ctrl+Shift+K, Tools -> Console)
  2. Type the following command (equal sign first): =<JavaScript Expression>

Example 1 - basic expression

=2+2

Example 2 - variables

=foo=15; 1337*(42+foo)

foo is a user defined variable (type =foo to display its value).

See all JavaScript Operators.

4 comments:

Thotheolh said...

How about using the 'script' command to do all these too ?

I think it's a bit weird to have some '='sign before any calculations you want to perform. Why not a something like python or ruby where you can python or ruby in the terminal and then off you go with all your expressions and calculations.

How about something like 'script' then following by 'foo=15' then followed by 'foo=foo+30' then the terminal prints 'foo=45' in return as an echo.

I noticed that the script function for the console is not well documented. How do I use it and is there more detailed examples ?

Thotheolh said...

I tried using script js and I could get the foo example I mentioned to work so why not just stick to the script js than to have some '=' sign thing .... or maybe how about playing for a calculator tool/widget ?

Konrad Twardowski said...

You can still use the old "script" command :) "=foo" is a much shorter version, useful for quick calculations.
The = prefix is required to avoid collision with other commands.

> I noticed that the script function
> for the console is not well documented.

To be fixed.

Thotheolh said...

I think this calculator would come in handy for anyone who likes to tinkle with the console (like me) and who wants a quick calculation when the situations arises.