Hi Jay (??),
Well, indeed there should have been some curly brackets in this example. I don't think the author left them out intentionally. It's not easy to keep the book 100% in sync with the code downloads, as lots of people deal with the book (copy editors, DTP guys, proof readers etc). Something has been mixed up somewhere.
Anyway, this is a known issue. If you look at the errata section (found
here), you'll find the corrected example:
Code:
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function checkCharType(charToCheck){
var returnValue = "O"
var charCode = charToCheck.charCodeAt(0);
if (charCode >= "A".charCodeAt(0) & charCode <= "Z".charCodeAt(0)){
returnValue = "U";
}else if (charCode >= "a".charCodeAt(0) & charCode <= "z".charCodeAt(0)){
returnValue = "L";
}else if (charCode >= "0".charCodeAt(0) & charCode <= "9".charCodeAt(0)){
returnValue = "N";
}
return returnValue;
}
//-->
</script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
var myString = prompt("Enter some text!", "Hello World!");
switch (checkCharType(myString)){
case "U":
document.write("First character was upper case.");
break;
case "L":
document.write("First character was lower case.");
break;
case "N":
document.write("First character was a number.");
break;
default:
document.write("First character was not a character or a number.");
}
//-->
</script>
</body>
</html>
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.