...

View Full Version : Newbie Question



sara jane
06-14-2010, 09:07 AM
Hi Everyone :)

I'm learning Javascript with varying degree's of success but am very much in the early phase.
My question/problem is this:


[ICODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script language="javascript" type="text/javascript">



var degFahren = new Array(212, "string data", -459.67);
var degCent = new Array();
var loopCounter;

for(loopcounter =0; loopCounter <= 2; loopCounter++){
if(isNaN(degFahren[loopCounter])){
alert("Data " + degFahren[loopCounter] + " at array index " +
loopCounter + " is invalid");
continue;
}
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>
/ICODE]

The following code does not return any errors in my browser but I'm confused since I'm sure I should be seeing an alert box telling me that there is invalid data entered bu this doesn't happen, also as far as I can make out I should only be receiving an error for the 2nd loop but there seem to be an error message returned for all 3 loops??

This is all possibly correct but I'm learning from a book and I have no-one to ask these mundane questions to. :(

Any help would be greatly received.

Sara

sara jane
06-14-2010, 09:09 AM
And if some-one could tell me where I'm going wrong with the code tags I'll be able to improve the presentation of any future posts.


:)

effpeetee
06-14-2010, 09:36 AM
Try this site for help. (http://www.jslint.com/)

JSLint expects the whole page code including the HTML

Frank

sara jane
06-14-2010, 09:48 AM
I'm sorry I thought this was a place to come for help.

Thanks...I guess

effpeetee
06-14-2010, 09:52 AM
I'm sorry I thought this was a place to come for help.

Thanks...I guess
No, please JSLint is offered for your help. It validates the javascript. It is the best that I can do. Also, any answer to you will keep your post alive.

There are many others here who can help you.

Frank

sara jane
06-14-2010, 10:11 AM
Hi,

Ok Frank, I've bookmarked that site and appreciate your help.
I have the web developer tool installed on firefox and will run a few test's to see if there are differences between the two.
I suppose I was just hoping some wise guru would be able to just sum up the problem in a line or 2.
As I said before according to my own debugger there are no errors in the code and I just wondered if the alert box doesnt always mean you will receive one, particularly as the code is run with an invalid number before the alert() function.

Again thanks for the link.

coothead
06-14-2010, 10:16 AM
Hi there sara jane,

and a warm welcome to these forums. ;)

you have a couple of typing errors in your code....


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<!--remove "language="javascript" it is deprecated -->
<script language="javascript" type="text/javascript">

var degFahren=new Array(212,"string data",-459.67);
var degCent=new Array();
var loopCounter;

//the "c" in first instance of "loopcounter=0" should be upperCase
for(loopcounter=0; loopCounter<=2;loopCounter++){
if(isNaN(degFahren[loopCounter])){
alert("Data "+degFahren[loopCounter]+" at array index "+loopCounter+" is invalid");
continue;
}
//the "c" in "degcent[loopCounter]" should be upperCase
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>

</head>

<body>

</body>
</html>

Make the changes and it should work OK. ;)

coothead

sara jane
06-14-2010, 11:58 AM
Hi coothead,

Works great, thanks alot slightly embarrassed by the the typing errors and in future if I post again I will double check for these first.

Thanks again :thumbsup:

coothead
06-14-2010, 12:07 PM
No problem, you're very welcome. ;)

p.s. Dno't feel ebmassrared by tpynig eorrrs, we all mkae tehm. :D

effpeetee
06-14-2010, 12:26 PM
No problem, you're very welcome. ;)

p.s. Dno't feel ebmassrared by tpynig eorrrs, we all mkae tehm. :D
Noonsens. eye nevre macke tiepin ore splelign erorrs. like. Innit?

Knarf



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum