![]() |
Array
The code that I have to work on is supposed to create an array so that when the user enters the number when prompted, it matches and displays the correct president. Right now, the prompt just continues and it ends with the whole list being displayed.
If anyone could give me some assistance with this, it would be greatly appreciated. Code:
<html> |
lots of mistakes.
And you really shouldn't be using prompt() or document.write() at all. Those are both considered obsolete. Plus, because your code uses document.write, there's no good way to allow the user to enter a number more than once. Anyway, for starters, kill you current method of creating the array. K.I.S.S. Code:
var presidents = [ "N/A", "Washington", "Adams", "Jefferson", ... ];And then put the choice in place using innerHTML or put it into another <form> field using .value. Oh, and there is no need for any FOR loop in your code, even if you don't use what I suggested. Dunno why you ever thought you needed one. |
Thanks, that helped a lot.
I know that a lot of the coding I've had to use isn't the way I should be doing it. But, my class is supposed to be going by the codes that are in our book (which has been super vague in my opinion)and I've been told by multiple people that they're obsolete. So, I've been having some trouble trying to stay in the guidelines of the book. I'm definitely starting to feel like it would just be better to do what I can in a more updated way instead of like this. But, again I do appreciate the help. |
Slightly off topic (Sorry!) but there is a very interesting article about JS Arrays here.
If you are a JS enthusiast (as I am) then consider javascriptweekly.com. |
Quote:
So long as students don't *DEMAND* that their schools teach them *MODERN* coding, then the schools will continue to allow lazy and incompetent instructors to choose to teach old style coding. So long as the instructors and schools don't DEMAND the publishers produce modern books, the publishers will continue to issue total crap. I wish you luck. |
Quote:
|
| All times are GMT +1. The time now is 10:19 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.