Back to the lesson

European weekday

importance: 5

European countries have days of week starting with monday (number 1), then tuesday (number 2) and till sunday (number 7). Write a function getLocalDay(date) that returns the “european” day of week for date.

let date = new Date(2012, 0, 3);  // 3 Jan 2012
alert( getLocalDay(date) );       // tuesday, should show 2

Open the sandbox with tests.

function getLocalDay(date) {

  let day = date.getDay();

  if (day == 0) { // 0 becomes 7
    day = 7;
  }

  return day;
}

alert( getLocalDay(new Date(2012, 0, 3)) ); // 2

Open the solution with tests in the sandbox.