DOTW Switch Statement

In this example below you will see how to do a DOTW Switch Statement with some HTML / CSS and Javascript

A very, very simple pen showing a template to get a daily special for a website. Used with heavy modification on a client's site as a simple sidebar component, shared to assist a local student with their own project.

Thumbnail
This awesome code was written by Isaac Doud, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright Isaac Doud ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>DOTW Switch Statement</title>
  
  
  
  
  
</head>

<body>

  <div id="specials-container">
<h1 id="specials-header">Today's Special:</h1>
<div id="specials"></div>
</div>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/cipherbeta/dotw-switch-statement-WzKEeN */
let restaurantInfo = {
  "dailyInfo": {
    "sunday": {
      "special": "Grilled Prime Rib Sandwich Special! An 8oz cut of Prime Rib, lightly grilled then topped with haystack onions and served on a toasted Ciabatta Roll.",
      "open-times": "11:00AM-9:00PM"
    },
    "monday": {
      "special": "Deep dish pizza! Only available on Mondays, our deep-dish crust is specially amde each Monday using a special rising process that creates a thick and fluffy pan-pizza, boldly seasoned and made to order and baked to perfection with the freshest ingredients!",
      "open-times": "11:00AM-9:00PM"
    },
    "tuesday": {
      "special": "We're closed today - sorry for any inconvenience!",
      "open-times": "We're closed today - sorry for any inconvenience!"
    },
    "wednesday": {
      "special": "Burger N' Brew Day! Each week we featgure a different specialy burger paired with a specialty Wisconsin-made craft beer.",
      "open-times": "11:00AM-9:00PM"
    },
    "thursday": {
      "special": "Lasagna Night (available beginning at 4:30PM). Served with sautéed vegetables and garlic bread!",
      "open-times": "11:00AM-9:00PM"
    },
    "friday": {
      "special": "Friday night fish fry featuring Beer-battered or broiled cod, breaded walleye, breaded or coconut shrimp. Also - we have our Weekly Seafood Special! Each week we feature a new seafood special like Crab Cakes with a Lemon-dill & Caper Sauce, Cajun Catfish, or pan-fried walleye, just to name a few! See our Facebook page for this week's special.",
      "open-times": "11:00AM-9:00PM"
    },
    "saturday": {
      "special":"Specialty pizza night featuring a pizza concoted with different sauce & ingredient combinations not available on the regular menu. See our Facebook page for this week's featured piza pie!",
      "open-times": "11:00AM-9:00PM"
    }
  }
}

let date = new Date();
let dayOfTheWeek = date.getDay();

switch(dayOfTheWeek){
  case 0:
    console.log("Sunday!");
    document.getElementById("specials").innerHTML = restaurantInfo.dailyInfo.sunday.special;
    break;
  case 1:
    console.log("Monday!");
    document.getElementById("specials").innerHTML = restaurantInfo.dailyInfo.monday.special;
    break;
  case 2:
    console.log("Tuesday!");
    document.getElementById("specials-header").innerHTML = restaurantInfo.dailyInfo.tuesday.special;
    break;
  case 3:
    console.log("Wednesday!");
    document.getElementById("specials").innerHTML = restaurantInfo.dailyInfo.wednesday.special;
    break;
  case 4:
    console.log("Thursday!");
    document.getElementById("specials").innerHTML = restaurantInfo.dailyInfo.thursday.special;
    break;
  case 5: 
    console.log("Friday!");
    document.getElementById("specials").innerHTML = restaurantInfo.dailyInfo.friday.special;
    break;
  case 6:
    console.log("Saturday!");
    document.getElementById("specials").innerHTML = restaurantInfo.dailyInfo.saturday.special;
    break;
  default:
    console.log("Nothing Returned");
    document.getElementById("specials-container").remove();
}

Comments