Hey, I’m still a bit stuck with the JS function that takes a string as an argument and returns a boolean indicating if the parameter string passed. There are some conditions, like:
A valid date string will have only the full month name(ex “January” not “Jan”), and a day. The string parameter can contain any number of spaces, but the month name must always start at the first non-space character from the beginning of the string.
So far it isn’t working properly…
function validateTheDate(string){
const months = {
January: {
end: 31
},
February: {
end: 28
},
March: {
end: 30
},
April: {
end: 31
},
May: {
end: 30
},
June: {
end: 31
},
July: {
end: 30
},
August: {
end: 31
},
September: {
end: 30
},
October: {
end: 31
},
November: {
end: 30
},
December: {
end: 31
}
}
let i = 0;
let extractedMonth = ‘’;
let extractedDay = ‘’;
while (string[i] === ’ ’ && i < string.length) i++;
while (string[i] !== ’ ’ && i < string.length) extractedMonth += string[i++];
while (string[i] === ’ ’ && i < string.length) i++;
while (string[i] !== ’ ’ && i < string.length) extractedDay += string[i++];
if (months[extractedMonth]) {
}else {
return false;
}
return true;
}