Build a Date Conversion Program - Build a Date Conversion Program

Tell us what’s happening:

I can’t pass 6 and 9, I’ve done everything possible
i console log it and it returns the proper task

Your code so far

const currentDate = new Date();

const options = {
  week: "short",
  month: "short",
  day: "2-digit",
  year: "numeric",
  hour: "2-digit",
  minute: "2-digit",
  second: "2-digit",
  timeZoneName: "short"
}

const formattedTime = currentDate.toLocaleString('en-US', options)

const currentDateFormat = `Current Date and Time: ${formattedTime}`

console.log(currentDateFormat)

function formatDateMMDDYYYY(data) {
  const format = data && data.date instanceof Date ? data.date : new Date()

  const month = String(format.getMonth() + 1).padStart(2, '0');
  const day = String(format.getDate()).padStart(2, '0');

  const year = String(format.getFullYear())

 return `Formatted Date (MM/DD/YYYY): ${month}/${day}/${year}`}

function formatDateLong(data){

  const date = new Date(data)
  const option = {
    month: "long",
    day: "numeric",
    year: "numeric"
  }

  const formatted = date.toLocaleString('en-US', option)

  return `Formatted Date (Month Day, Year): ${formatted}`
}

console.log(formatDateMMDDYYYY())

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:144.0) Gecko/20100101 Firefox/144.0

Challenge Information:

Build a Date Conversion Program - Build a Date Conversion Program

Could you explain what format is in the formatDateMMDDYYYY function?

it’s used to check if data exist and data.date is a valid date object, even without the format line, it still doesn’t pass the 6 and 9

Can you explain what it is for though instead of what the code literally says? Why do you need the check and how does it work?

.padStart(2, ‘0’) ensure that its padded to two digits since it is DD and MM but even with the short form const month = getMonth() it still doesn’t pass