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