Wednesday, 28 August 2013

Can't get if statement to compare two strings in javascript

Can't get if statement to compare two strings in javascript

In my code when i equals 5 myDate should be equal to it. The alert shows
me that they are the same. I can never get the function to return 1;
function checkForHoliday(date) {
var myDate = new Date(date);
myDate = myDate.getMonth() + "/" + myDate.getDate() + "/" +
myDate.getFullYear();
alert(myDate + "\n" + holidays[5]);
for (i = 0; i <= 9; i++) {
if (myDate == holidays[i]) {
return 1;
alert("got it");
}
}
return 0;
}
This is what the string in the array looks like:
year = 2013
holidays[5] = "7/2/" + year
My alert shows me this:

No comments:

Post a Comment