Wrox Programmer Forums
|
BOOK: Beginning JavaScript
This is the forum to discuss the Wrox book Beginning JavaScript by Paul Wilton; ISBN: 9780764544057
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 18th, 2003, 03:22 PM
Authorized User
 
Join Date: Nov 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 4 example 1

What is up with this one? Did the author just figure he would leave out all the closing curly brackets without mentioning it? Not a cool thing to do to a beginner. (page 121).

 
Old November 18th, 2003, 04:43 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Would you mind posting the code of the example here? Maybe it's not an error; the curly brackets are not always required......


Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 19th, 2003, 12:34 PM
Authorized User
 
Join Date: Nov 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's the code that I typed from the book. Heck, maybe I had a type-o and it would have worked without the curly brackets. It's just when I downloaded the code from the site it looked totally different than what was in the book. I've already moved past this anyway so don't bother spending much time on it BUT I appreciate the response and help. THANKS !!

<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>


 
Old November 19th, 2003, 01:39 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
chapter 7 - chapter 11 pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 3 January 6th, 2008 11:40 AM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.