If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Javascript Check - Unsure of wrong code

Hi there everyone,

I check this forum quite often when I am in need to HTML of Javascript help as I am still learning. I am now follow the Missing Guide books to learn Javascript, after feeling that the Murach books were a little hard to follow.

My questions is: I was following an example in the book, because loops are still somewhat bugging me, and I wrote down the code word for word and cannot figure out the problem with the code. I put it throught a debugger, and it was saying that the 'answer' variable was not defined, although it had been on the line before it. This is taken straight from the book, which is why I am slightly confused and having trouble.

By the by, you really ought to stop using that book. It is teaching you obsolete and pretty useless JavaScript. Any time you see code using alert() or prompt() or confirm() or document.write(), it is time to RUN AWAY from that code/book/tutorial.

Learn to match up all your delimiters. You should have the same number of { as you have }, same number of ( as you have ), etc.

Code:

var answer = prompt(question[0]),'');

In that line, how many ( are there?
How many ) are there?

Enough said?

Excellent! Thanks. I guess that one slipped by me. Also thank you for your reference for the website! I am definitely going to check it out. I think I started to use this book because it was one that could get me going the easiest.

I used to do Javascript, or at least some basic javascript, but needed a kick start and it was good enough to do that. The website you gave me though seems really good and I will probably just use that from now on.

Here is what the CHROME browser shows for alert( ) and prompt( ) calls:

If the user checks that checkbox, *KABLOOEY*. He/she no longer sees ANY alert/prompt/confirms.

Also, the alert/prompt appears in the top center of the current window and, as you can see, is really really *UGLY*.

So if you really want CRAPPY looking web pages with ugly looking boxes that the user can easily turn off and/or where the user can just turn off JavaScript completely, then go ahead and keep using alert/prompt/confirm. If you want web pages that *WORK* and that look good, then expend a tiny modicum of effort and do things right.

Oh, and by the by:

but no one has given me a good reason why.

Then clearly you haven't bothered reading the HUNDREDS of times that Felgall (and others) have explained this before. Now that you have had the message personally delivered, you can't use that excuse any more.