Wrox Programmer Forums
|
BOOK: Beginning JavaScript 2nd Edition For questions about Beginning Javascript 2nd Edition by Paul Wilton. (ISBN: 0-7645-5587-1). Published April 2004. For Javascript questions not specific to this book, please see the Javascript forum. If you have the 1st edition, please continue to use that forum instead at: http://p2p.wrox.com/forum.asp?FORUM_ID=21
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript 2nd Edition 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 September 14th, 2005, 02:12 PM
Registered User
 
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question chp3 pg 81

The exercise Try it out about the switch command. I don't understand
why the secretNumber is equal to 3. Why not 4 or 2?

<HTML>
<BODY>

<SCRIPT LANGUAGE=JavaScript>

var secretNumber = prompt("Pick a number between 1 and 5:", "");
secretNumber = ParseInt(secretNumber);

switch (secretNumber)
{
case 1:
   document.write("Too low!");
   break;

case 2:
   document.write("Too low!");
   break;

case 3:
   document.write("You guessed the secret number!");
   break;

case 4:
   document.write("Too high!");
   break;

case 5:
   document.write("Too high!");
   break;

default:
   document.write("You did not enter a number between 1 and 5.");
   break;
}
document.write("<BR>Execution continues here");

</SCRIPT>

</BODY>
</HTML>

 
Old March 3rd, 2006, 09:57 AM
Registered User
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When case 2 and case 4 are tested they return the values 'Too low!' and 'Too high!' respectively.
This means that the number has to be between 2 and 4, which only leaves 3.
Does that help?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 4 Pg 117 Try It Out Panel Display Question workib BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 April 8th, 2008 01:06 AM
CH 3 pg 96 Question mririe BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 8 August 25th, 2004 04:17 AM
quick question about code on pg 171 phpnewbie BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 August 24th, 2004 11:51 AM
Chp3, pg 100. Strange behavior brandonsaxe BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 20 November 3rd, 2003 07:26 PM





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