0

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);
Soy__Boi
  • 3
  • 3
  • It works perfectly fine. Did you forget to URL encode the code? – Sebastian Simon Jan 12 '23 at 23:17
  • The correct bookmarklet is generated by ``encodeURI(`javascript:${yourCodeAsAStringHere}`)``. The correct bookmarklet is therefore `javascript:var%20pv%20=%20prompt('principal');%0Avar%20rate%20=%20prompt('rate');%0Arate%20=%20rate/100;%0Avar%20time%20=%20prompt('time');%0Avar%20fv%20=%20pv*(1%20+%20rate)**time%0Aalert(fv);`. – Sebastian Simon Jan 12 '23 at 23:25

1 Answers1

-1

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.

dave
  • 62,300
  • 5
  • 72
  • 93