# 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. // 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 after1 = amt*(1.0 + rate/100.0); var after2 = after1*(1.0 + rate/100.0); var after3 = after2*(1.0 + rate/100.0); var after4 = after3*(1.0 + rate/100.0); var after5 = after4*(1.0 + rate/100.0); var after6 = after5*(1.0 + rate/100.0); var after7 = after6*(1.0 + rate/100.0); var after8 = after7*(1.0 + rate/100.0); var after9 = after8*(1.0 + rate/100.0); var after10 = after9*(1.0 + rate/100.0); alert(amt + " dollars at " + rate + " percent for 10 years is " + after10);
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"); ```
``` ```