# A Simple Javascript Program Interpreter

 Program Error Messages 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 // This program reads in a dollar amount and // annual interest rate and prints out what you'd // have at that rate starting with that amount with // 10 years of annually compounded interest. // NOTE: this version continually reassigns to variable tot. // Read amount of money and rate var amt = prompt("Enter dollars deposited"); var rate = prompt("Enter annual interest rate"); // Compute compound interest for 10 years. var tot = amt; tot = tot*(1.0 + rate/100.0); tot = tot*(1.0 + rate/100.0); tot = tot*(1.0 + rate/100.0); tot = tot*(1.0 + rate/100.0); tot = tot*(1.0 + rate/100.0); tot = tot*(1.0 + rate/100.0); tot = tot*(1.0 + rate/100.0); tot = tot*(1.0 + rate/100.0); tot = tot*(1.0 + rate/100.0); tot = tot*(1.0 + rate/100.0); alert(amt + " dollars at " + rate + " percent for 10 years is " + tot);
Javascript Cheat Sheet
• arithmetic: `+ - * / %`←means remainder. There's no ^ for exponentiation!
• math functions: ```Math.sin( ), Math.cos( ), Math.log( ), Math.exp( ), Math.sqrt( ), Math.floor( )```
• ``` math constants: Math.PI, Math.E variables: define like var x; or var x = 0;. Assign like x = x + 1; semicolon: use ; to terminate statements, e.g. var x; x = 17; string literals: "hi" or 'hi' or 'I said "hi", right?' escaping: within a string literal, \" for ", \' for ', \\ for \, \n for newline string operations: "a" + "b" → ab, "foobar"[3] → b, "foobar".length → 6 strings and ASCII: typeof: returns type name as a string, e.g. typeof(43*7) → Number conversions: String-to-Number String(42), Number-to-String Number("42") alert: display pop-up window with text, e.g. alert("Hello World!"); prompt: get string from user via pop-up window, e.g var n = alert("Enter your name"); ```
``` ```