# Functions
Use more functions.
> /**
* Confirm that all dates are valid Date values and that they follow business rules before proceeding to calculations.
*/
if ( termInYears < 0 ) {
window.alert("Term in years must be greater than zero.")
}
else if ( !isValidDate(productPurchaseDate) ) {
window.alert("Invalid ProductPurchase Date.");
}
else if ( !isValidDate(contractPurchaseDate) ) {
window.alert("Invalid Contract Purchase Date.");
}
else if ( !isValidDate(cancelDate) ) {
window.alert("Invalid Cancel Date.");
}
else if ( cancelDate < productPurchaseDate || cancelDate < contractPurchaseDate ) {
window.alert("Cancel date cannot be prior to Product or Contract purchase date.");
}
else if ( cancelDate > expirationDate ) {
window.alert("Cancel date cannot be past Expiration date.");
}
/**
* Confirm that all numbers are valid numbers for calculations.
*/
else if ( isNaN(purchasePrice) || isNaN(termInYears) || isNaN(amtPaidInClaims) || isNaN(gracePeriodInDays) ) {
window.alert("Invalid Number Entry. Please check your entries and try again.");
}
This is one example of a place you could use another function. You can split that off into an `isValidInput()` function, perhaps, and call that by itself and get rid of the `if`/`else if`/`else` structure at the beginning of `calculateProratedRefund()`, replacing it with something like this:
if (!isValidInput()) { return }
// other code here