Switch/Case
Menu The Switch Case
 

Case Structure in Javascript

When I was using this on my contextual page headings page it was not working on an iPad but was on a Windows computer.

I want to use this page to demonstate the w3-code container.

Examples from W3C page

Above is an empty paragraph. Well, actually it echos the date until the button is clicked

The tag openings < need to be changed to &lt;

The JavaScript (need to add br tags)

function myFunction() {
var text;
switch (new Date().getDay()) {
case 6:
text = "Today is Saturday";
break;
case 0:
text = "Today is Sunday";
break;
default:
text = "Looking forward to the Weekend";
}
document.getElementById("demo").innerHTML = text;
}
Top

The code is hi-lighted using www.w3schools.com/lib/w3codecolor.js

The use of the pre tag maintains the indenting and you don't need the line breaks - However, it doesn't wrap on small screens

The JavaScript using the pre tag (no br tags)

function myFunction() { 
var text; 
switch (new Date().getDay()) {
  case 6:
    text = "Today is Saturday"; 
    break; 
  case 0: 
    text = "Today is Sunday";
    break;
  default:
    text = "Looking forward to the Weekend";
}
document.getElementById("demo").innerHTML = text;
}

Links

Top

External Links - references -

  • 1 - The JavaScript Switch Statement - https:// www.w3schools.com/js/ js_switch.asp
  • 2 - The W3-Code container - https:// www.w3schools.com/w3css/ w3css_references.asp#container

Site design by Tempusfugit Web Design -