6-1 Future Value the First
I think I had difficulty with this simply because of the bad web design on the html portion. I really hate the way they abused that drop box. Drop boxes are for discrete values (IE you can get this car in Red, Blue, Green) - not numbers. Use a text box for numeric values (at least in the sense of the assignment - which was what amount was going to be invested.)
I got hung up a bit on typing. I'm used to languages (IE "C") that type at declaration. I'm not sure what the default typing is for Javascript (huh - apparently it's "dynamic") - but it really screwed me up in the first assignment. Not a big deal though.
7-2 Future Value the Second
This has been a cakewalk so far, but I'm still working on the difficult bit. It starts out letting the user input an initial investment, interest rate, and number of years. At first, the assignment calls for you to break the script by generating values too large for Javascript to deal with. Then it has you kill the loop (you switch the value for "i"), and return a message to the user via the alert method. Then it gets interesting.
We change the text boxes from user input to a random number generator (a function for this is provided in the example source), and then have to set up the calculate function to use it properly. After that, you have to format the output with a dollar sign, commas in the expected places and a decimal point. I think I see how this will be accomplished.
Okay, what I'm doing is this. Create variables for cents, hundreds (covers ones, tens, hundreds), thousands (thousands, ten thousands, hundred thousands), and millions. I'm also creating a variable to store the index - which is the decimal point. That will be decimalPoint = futureValue.indexOf("."). From there cents = futureValue.subscript(decimalPoint+1, decimalPoint+2). Where I'm dicey is whether you can use negative values in the attributes but if you can it'll go like this:
- hundreds = futureValue.subscript(decimalPoint - 1, decimalPoint - 3)
- thousands = futureValue.subscript(decimalPoint - 4, decimalPoint - 6)
- millions = futureValue.subscript(decimalPoint - 7, decimalPoint - 9)
This should provide enough places, but then we have to test for millions and I think that's a place I may have difficulty. My thinking is that before the branch, use parseFloat on futureValue and test it to see if it contains a value greater than 999,999.99 - if so it'll output with the millions place, if not, we don't include it.
Okay, game on. I'll update this when I see how it works out.
No comments:
Post a Comment