You could consider
placeholderattributes in the input fields on your HTML to display the format of the data that should be entered.Your closing
</style>tag isn't indented on the same level as the opening tag, it should be.Style-wise, It's easier on people if you can align all your
<input>s to the same vertical values, rather than based on the length of the description.You have extraneous whitespace in some of your brackets:
if ( finalRefund < 0.0 ), should be:
if (finalRefund < 0.0)if (finalRefund < 0.0)The naming behind
outputParcould be improved;outputParagraph: for example.Rather than repeating
outputPar.appendChild()over and over, move it to an array, and do it in a loop:outputPar.appendChild(document.createTextNode("Product Purchase date: " + formatDate(productPurchaseDate))); outputPar.appendChild(document.createElement("br"));like:
var contentToBuild = [ "Product Purchase date: " + formatDate(productPurchaseDate), // More here ]; contentToBuild.forEach(function(element){ outputParagraph.appendChild(document.createTextNode(element)); outputParagraph.appendChild(document.createElement("br")); });
outputPar.appendChild(document.createTextNode("Product Purchase date: " + formatDate(productPurchaseDate))); outputPar.appendChild(document.createElement("br")); like:
var contentToBuild = [ "Product Purchase date: " + formatDate(productPurchaseDate), // More here ]; contentToBuild.forEach(function(element){ outputParagraph.appendChild(document.createTextNode(element)); outputParagraph.appendChild(document.createElement("br")); }); - Your usage of brackets around math operations is inconsistent:
Your usage of brackets around math operations is inconsistent:
var msPerDay = (1000 * 60 * 60 * 24); var termLeft = 1.0 - termUsed;I'd suggest sticking to the same usage throughout, the brackets seem clearer, but often aren't required.
var msPerDay = (1000 * 60 * 60 * 24); var termLeft = 1.0 - termUsed; I'd suggest sticking to the same usage throughout, the brackets seem clearer, but often aren't required.
isValidDate()could use some re-arranging.isValidDate()could use some re-arranging.function isValidDate(date) { "use strict"; if ( Object.prototype.toString.call(date) !== "[object Date]" ) { return false; } else if ( isNaN(date.getTime()) ) { return false; } else { return true; } }Rather than testing
isNaN(date.getTime())second, test it first, and remove it from theif-elseblock.Then, you can simply
returnthe boolean value ofObject.prototype.toString.call(date) !== "[object Date]"into:
function isValidDate(date) { "use strict"; if (isNaN(date.getTime())) { return false; } return (Object.prototype.toString.call(date) === "[object Date]"); }Note that, in your code, you test against negatively (
!==) the variable, and returnfalse. It'd be easier, in future, if you test against positively (===) and returnedtrue.
function isValidDate(date) { "use strict"; if ( Object.prototype.toString.call(date) !== "[object Date]" ) { return false; } else if ( isNaN(date.getTime()) ) { return false; } else { return true; } } Rather than testing isNaN(date.getTime()) second, test it first, and remove it from the if-else block.
Then, you can simply return the boolean value of Object.prototype.toString.call(date) !== "[object Date]".
into:
function isValidDate(date) { "use strict"; if (isNaN(date.getTime())) { return false; } return (Object.prototype.toString.call(date) === "[object Date]"); } Note that, in your code, you test against negatively (!==) the variable, and return false.
It'd be easier, in future, if you test against positively (===) and returned true.