Search the Community
Showing results for tags 'switch'.
-
The Switch Conditional exercise on pages 143 - 150 makes us of an undefined variable, var cost; and I'm not sure what role it plays in the code. Do the cost elements in the switch statements load the value into the undefined variable var cost depending upon which condition is met in the document's type value? I can remove these two lines of code, as well as the undefined variable, var cost, and still see the membership form run: var type = document.getElementById('type'); var years = document.getElementById('years'); Why did we create a reference to the document element years when it seems not to be used in the script? Many mysteries have unfolded in this exercise.
-
I've never seen this variation of the switch statement, could you guys please comment on it? switch ($language) { case 'German': echo 'Hallo, Welt!'; break; case 'Italian': echo 'Ciao, mondo!'; break; case 'Spanish': echo 'Hola, mundo!'; break; case 'English': default: echo 'Hello, world!'; break; } What surprised me is the last four lines: case 'English': default: echo 'Hello, world!'; break; I thought the default should be set without mentioning the case before. Is that a legitimate way of doing things or just a typo in the book?