Write a function that converts user entered date formatted as M/D/YYYY to a format required by an API (YYYYMMDD). The parameter "userDate" and the return value are strings. For example, it should convert user entered date "12/31/2014" to "20141231" suitable for the API. i tried:
function formatDate(userDate) {
// format from M/D/YYYY to YYYYMMDD
a = new Date(userDate);
y = a.getFullYear();
m = a.getMonth();
d = a.getDate();
return y.toString() + m.toString() + d.toString();
}
console.log(formatDate("12/31/2014"));
where is the problem??