javascript

A General Discussion forum for cars and other topics, and a great place to introduce yourself if you are new to NICO!
lessthanjakejohn
Posts: 4105
Joined: Fri Oct 25, 2002 6:39 am

Post

I'm just starting to learn JavaScript and I can't get this code to work grrrrrrr

<html>

<head><title>ch 2 ex 1</title></head>

<body>

<script language="javascript" type="text/javascript"><!--

const MY_CONST = 12;var myVariable;myVariable = 10;myVariable = myVariable + MY_CONST;

alert(myVariable);

//--></script>

</body></html>

any ideas???


User avatar
Rex
Posts: 16845
Joined: Sat Apr 05, 2003 6:50 pm
Car: None
Location: South of ATL
Contact:

Post

I don't see any simple spelling/format/context errors, and that's almost always what I mess up :).

Try this reference http://jibbering.com/faq/

User avatar
blink0r
Posts: 1161
Joined: Sun Aug 04, 2002 11:55 am
Car: Turbo(s), making fun of Daunttless, naked girls, and guitar.
Contact:

Post

I can't find anything wrong with it personally, but i think the problem may be with the alert you're trying to do

lessthanjakejohn
Posts: 4105
Joined: Fri Oct 25, 2002 6:39 am

Post

i think my browser does not support const command :(

dunno

lessthanjakejohn
Posts: 4105
Joined: Fri Oct 25, 2002 6:39 am

Post

ok look at the source of this file...all I did was change const to var

http://johnp.opendns.be/index.htm

User avatar
nomuken
Posts: 436
Joined: Sat May 03, 2003 5:12 pm

Post

Your code runs fine under Mozilla/Netscape, but not under IE. To stop IE from producing an error replace

const MY_CONST = 12;

with

MY_CONST = 12;

(friggin' Micro$oft :rolleyes)

lessthanjakejohn
Posts: 4105
Joined: Fri Oct 25, 2002 6:39 am

Post

ya thanks...but its effectively is the same as

var MY_CONST = 12

BuudWeizErr
Posts: 4745
Joined: Tue Sep 24, 2002 11:35 am

Post

Doesn't the script information need to go in the head, not the body? It's the output that needs to go in the body.

lessthanjakejohn
Posts: 4105
Joined: Fri Oct 25, 2002 6:39 am

Post

Doesn't matter for something as simple as this


Return to “General Chat”