DEV Community

Milan Matejic
Milan Matejic

Posted on

JavaScript assignments - 2

This blog posts introduce another simple JavaScript assignment and solution for it.

This assignment is great to practice JavaScript and develop problem solving thinking.

As usual, if you have a another solution, please write it in the comment section.

Assignment:
Write a JavaScript program to get the current date.

Expected output:
mm-dd-yyyy, mm/dd/yyyy or dd-mm-yyyy, dd/mm/yyyy


const dateFormat = (date = new Date()) {
const days  = date.getDate();
const months = date.getMonths() + 1; 
//because months are 0 based (January is number 0)
const years = date.GetFullYears();
   return `${months}-${days}-${years}`
}`
console.log(dateFormat());
//4-9-2021





Enter fullscreen mode Exit fullscreen mode

Top comments (0)