First day of May, the sun is shining, the laundry is on the line, there are herbs to be planted, it's time to keep your appointment with the Wicker Man, and I...am learning JavaScript. I do it to myself, and that's what really hurts. The JavaScript Switch StatementSo apparently, switch is more readable than having a bunch of if and else statements. Which I can understand, because, yeah, the more complicated your JavaScript is, the more complicated that becomes. And the example they use explains it nicely. let day; let date = new Date().getDay(); switch (date) { case 0: day = "Sunday"; break; case 1: day = "Monday"; break; case 2: day = "Tuesday"; break; case 3: day = "Wednesday"; break; case 4: day = "Thursday"; break; case 5: day = "Friday"; break; case 6: day = "Saturday"; } document.getElementById("demo").innerHTML = "Today is " + day; I also like how they bring in getDay which returns the day of the week as a number, starting with "Sunday = 0". So, theoretically, I could take the…
No comments yet. Log in to reply on the Fediverse. Comments will appear here.