Rosetta Code: Date format

Tell us what’s happening:

I am getting “message: getDataFormats() should return [“2019-1-15”, “Tuesday, January 15, 2019”].” when I run the tests against the Rosetta Code: Date format challenge, yet when using console.log(), the array looks correct.

Your code so far

function getDateFormats () {
  // Good luck!
  let dateTime = new Date;
  let newArray = [];
  const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  const dayNames = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

  let firstSpot = dateTime.getFullYear() + '-' + (1 + dateTime.getMonth()) + '-' + dateTime.getDate();
  // Push to array

  let secondSpot = dayNames[dateTime.getDay()] + ', ' + monthNames[dateTime.getMonth()] + ' ' + dateTime.getDate() + ', ' + dateTime.getFullYear();
  // Push to array

  console.log("Array: " + newArray);

  return newArray;


// Error when running test
//message: getDataFormats() should return ["2019-1-15", "Tuesday, January 15, 2019"].

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:

When I run you code, it says it’s Wednesday.

@ArielLeslie Thank you. You made me realize that I was over looking the actual value. I started the dayNames array on Monday and not Sunday. When I move Sunday to the 0 index, it solve the issue.

Thank you.

I’m glad I could help. Happy coding!