I often lose track of the days. Since I am learning Javascript, figured I'd write a function that helps me remember! :D
Created
March 27, 2022 06:57
-
-
Save fyrfli/637d6645d8360a42323b0aed1487fd13 to your computer and use it in GitHub Desktop.
WTH is Today?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button type="submit" id="getday">What day is it today?</button> | |
<div id="today"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment