Search code examples
javascriptbookmarklet

Javascript working properly in console, but not as bookmarklet


I wrote a relatively simple program designed to calculate annual compound interest, and while it worked in google chrome's console, when I converted it into a bookmark it would still give me the prompts, yet not the final result. I was wondering if I am supposed to format it differently, or if this is impossible.

Here is my code:

var pv = prompt('principal');
var rate = prompt('rate');
rate = rate/100;
var time = prompt('time');
var fv = pv*(1 + rate)**time
alert(fv);

Solution

  • As a bookmarklet it will all be on a single line, so you need to have a semicolon after this line:

    var fv = pv*(1 + rate)**time;
    

    Then it will work.