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 January 13th, 2004, 09:52 PM
Authorized User
 
Join Date: Nov 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question about how it works

Hello again all. Trying to learn this again and just have a question of where the value is being used/stored in the code below. Yes, it's the same Chapter 4 question 1 that I complained about before but now I have actually taken my time and understand chapter 1-3 :)

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

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");
}

I left out the top tags to save space. I totally understand how this is working for the most part but my question is this. Our checkCharType function is getting a value and returning it in the "returnValue" variable. But where exactly is it returning it to? I don't see any reference of that again in the code. I realize it is getting passed down to the switch statement to check against myString but I'm unclear about where it goes. Sorry for the dumb question but it's the little things like this that get me hung up. Thanks in advance.

 
Old January 14th, 2004, 05:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Would it make more sense if it read:
var theReturnValue = checkCharType(myString);
switch (theReturnValue)
{
...

That's all its doing - using the return value for the switch statement only, then its discarded. If you like you can think of JS creating a temporary variable in memory containing the return value.

hth
Phil
 
Old January 14th, 2004, 02:32 PM
Authorized User
 
Join Date: Nov 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey thanks a million Phil - that totally helps out. Much appreciated.






Similar Threads
Thread Thread Starter Forum Replies Last Post
how cache works Maxxim BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 October 30th, 2007 01:09 PM
Works in IE but not in FF sofiacole Pro JSP 1 September 12th, 2007 11:20 PM
how does this sample works? dsmportal ASP.NET 2.0 Professional 0 August 3rd, 2006 08:15 PM
works bryan.lugo Excel VBA 0 April 19th, 2006 02:47 PM
will the session works? rekha_jsr Classic ASP Basics 3 December 10th, 2004 02:02 AM





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