Date Time
This code should show the current date in MONTH DAY(suffix) YEAR (YYYY)
Exemple: January 4th 2024
Useful in web when you want to make a current date shown automatically!
function ShowDate() {
const currentDate = new Date();
const monthsOfYear = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
const currentMonth = monthsOfYear[currentDate.getMonth()];
const currentDay = currentDate.getDate();
let daySuffix;
switch (currentDay) {
case 1:
case 21:
case 31:
daySuffix = "st";
break;
case 2:
case 22:
daySuffix = "nd";
break;
case 3:
case 23:
daySuffix = "rd";
break;
default:
daySuffix = "th";
}
const currentYear = currentDate.getFullYear();
return `${currentMonth} ${currentDay}${daySuffix} ${currentYear}`;
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
});
});