Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 14th, 2012, 01:14 PM
vinnythestick vinnythestick is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 5 vinnythestick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 15 sec
Reputation Power: 0
Switches in Javascript

Hello! This is my first post so I'd like to start by thanking the team here at Dev Shed for their work, and I'd also like to thank the open source community as well for all the help I'll undoubtedly receive along the way.

With that being said, I just wrote my very first switch in javascript and it looks like so...

Code:
var die=Math.ceil(Math.random()*6);
var output="";
switch (die){
	case 1:
	output="I";
	break;
	case 2:
	output="II";
	break;
	case 3:
	output="III";
	break;
	case 4:
	output="IV";
	break;
	case 5:
	output="V";
	break;
	case 6:
	output="VI";
	break;
	default:
	output = "PROBLEM";
}
alert(output);


The good news is that the code works fine.

I pulled the code straight out of Javascript for dummies and the final line of code
Code:
alert(output);

wasn't in the book. I had some trouble figuring out how to make the code show up in the browser but figured it out after a few minutes.


My question is... Do switches automatically generate client-side alerts? Or was there an error in the writing of the book?

From what I've gathered in the book, the author would lead me to believe that my last piece of code wasn't necessary, and the alert would automatically be generated, but after trying it in 4 browsers i can say with certainty that the code wouldn't generate an alert until after i amended it.

My reason for asking is that I want to ensure i have a thorough knowledge of exactly what why and how i'm learning web development.

Thanks,
Vin

Reply With Quote
  #2  
Old March 14th, 2012, 04:44 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,694 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 4 h 18 m 35 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
You are correct: the browser won't show any alert()s unless you specifically tell it to show one.

Printed books often have mistakes. Take what they say with a grain of salt and independently verify what they tell you. Also check their website(s) for errata sections: there may be mistakes but they'll often address them after publishing.

Reply With Quote
  #3  
Old March 14th, 2012, 05:18 PM
vinnythestick vinnythestick is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 5 vinnythestick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 15 sec
Reputation Power: 0
I figured as much...

Thank you requinix for the information!

Reply With Quote
  #4  
Old March 16th, 2012, 08:47 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,804 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 17 h 28 m 32 sec
Reputation Power: 6112
It's also possible they weren't going to output anything until later in the chapter. People get confused when you say:

"Now you're going to output it to make sure it works. I know it WILL work, since I wrote it and tested it before I gave it to you, but I'm trying to teach you good debugging. No, there's no bugs. Just alert it. See? Now delete it. The alert. No not the whole thing. Because we needed the alert for debugging. No, of course there's no bugs in THIS, but in the future...No, bugs won't magically appear in this code in the future, I meant in YOUR future. You know what, just move on."
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
  #5  
Old March 16th, 2012, 07:05 PM
vinnythestick vinnythestick is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 5 vinnythestick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 15 sec
Reputation Power: 0
Wait? So there's a bug in my code?

Lol jk jk

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Switches in Javascript

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap