Skip to content

Instantly share code, notes, and snippets.

@fyrfli
Created March 27, 2022 06:57
Show Gist options
  • Save fyrfli/637d6645d8360a42323b0aed1487fd13 to your computer and use it in GitHub Desktop.
Save fyrfli/637d6645d8360a42323b0aed1487fd13 to your computer and use it in GitHub Desktop.
WTH is Today?
<button type="submit" id="getday">What day is it today?</button>
<div id="today"></div>
document.getElementById("getday").onclick = function () {
const today = new Date();
const theDaye = today.getDay();
let message = "Today is ";
switch (theDaye) {
case 0:
message += "Sunday!";
break;
case 1:
message += "Monday!";
break;
case 2:
message += "Tuesday!";
break;
case 3:
message += "Wednesday!";
break;
case 4:
message += "Thursday!";
break;
case 5:
message += "Friday!";
break;
case 6:
message += "Saturday!";
break;
default:
message = "No such day exists";
}
document.getElementById("today").innerHTML = message;
};
body {
width: 380px;
margin: 80px auto;
text-align: center;
}
#getday {
padding: 10px;
border-radius: 20px;
background-color: olive;
color: lemonchiffon;
font-size: 20px;
border: 1px solid olive;
margin: 2rem auto;
}
#today {
margin: auto;
font-size: 36px;
color: darkgreen;
}

WTH is Today?

I often lose track of the days. Since I am learning Javascript, figured I'd write a function that helps me remember! :D

A Pen by fyrfli on CodePen.

License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment