Step 5

Let's validate the expiration date.

const month = document.getElementById("month").value;
const year = document.getElementById("year").value;
// FIXME: thie following does not account for edge cases!
if (new Date() > new Date(year, month)) {
  window.alert("Your card is expired!");
  return;
}

Add the above snippet to handleFormSubmit as shown below:

function handleFormSubmit(event) {
  event.preventDefault();

+ const month = document.getElementById("month").value;
+ const year = document.getElementById("year").value;
+ if (new Date() > new Date(year, month)) {
+   window.alert("Your card is expired!");
+   return;
+ }

  window.alert("Thanks for the payment!");
}

Here is the payment form in action: