kingnutter Posted March 15, 2008 Share Posted March 15, 2008 Hi Everyone, I've typed this example from "Beginning Javascript" and it doesn't seem to work: [pre]<html> <head> </head> <body> <script language=JavaScript type="text/javascript"> var degFahren = new Array(212, 32, -459.15); var degCent = new Array(); var loopCounter; for (loopCounter = 0; loopCounter <= 2; loopCounter++) { degCent[loopCounter] = 5/9 * (degFahren[loopCounter] - 32); } for (loopCounter = 2; loopCounter >= 0; loopCounter--) { document.write("Value " + loopCounter + " was " + degFahren[loopCounter] + " degrees Fahrenheit"); document.write(" which is " + " degCent[loopCounter] + " degrees centigrade<BR>");[pre][/pre] } </script> </body> </html>[/pre] Nothing is mentioned in the online erratum. However this very similar program cut and pasted from the internet DOES work: [pre] <HTML> <HEAD> <TITLE>for example</TITLE> </HEAD> <BODY> <SCRIPT LANGUAGE=JavaScript> var degFahren = new Array(212, 32, -459.15); var degCent = new Array(); var loopCounter; for (loopCounter = 0; loopCounter <= 2; loopCounter++) { degCent[loopCounter] = 5/9 * (degFahren[loopCounter] - 32); } for (loopCounter = 2; loopCounter >= 0; loopCounter--) { document.write("Value " + loopCounter + " was " + degFahren[loopCounter] + " degrees Fahrenheit"); document.write(" which is " + degCent[loopCounter] + " degrees centigrade<BR>"); } </SCRIPT> </BODY> </HTML>[/pre] I'm pretty sure it is because in the former the <= sign opens as an html tag, but I can't see what the difference between the two sets of codes is except a different case in the head of the latter and different script language definitions. I am typing and testing the code in HyperEdit on a MacBook and also testing on Firefox with the same results. Any ideas? Quote Link to comment Share on other sites More sharing options...
kingnutter Posted March 15, 2008 Author Share Posted March 15, 2008 I forgot to say that I have already tried putting the code within HTML comment tags and it has no effect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.