Skip to main content
added 140 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
  • You could consider placeholder attributes 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 outputPar could 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 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.

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.

  • You could consider placeholder attributes 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)

  • The naming behind outputPar could 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")); }); 
  • 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.

  • 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 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.

  • You could consider placeholder attributes 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) 
  • The naming behind outputPar could 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")); }); 
  • 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.

  • 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 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.

added 4 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 70
  • 155
var contentToBuild = [ "Product Purchase date: " + formatDate(productPurchaseDate), // More here ]; contentToBuild.forEach(function(element){ outputParagraph.appendChild(document.createTextNode(element)); outputParagraph.appendChild(document.createElement("br")); }); 
contentToBuild = [ "Product Purchase date: " + formatDate(productPurchaseDate), // More here ]; contentToBuild.forEach(function(element){ outputParagraph.appendChild(document.createTextNode(element)); outputParagraph.appendChild(document.createElement("br")); }); 
var contentToBuild = [ "Product Purchase date: " + formatDate(productPurchaseDate), // More here ]; contentToBuild.forEach(function(element){ outputParagraph.appendChild(document.createTextNode(element)); outputParagraph.appendChild(document.createElement("br")); }); 
removed mistake
Source Link
Quill
  • 12.1k
  • 5
  • 41
  • 94
  • You could consider placeholder attributes 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)

  • parseFloat(daysElapsed / 365).toFixed(2): Note that leap years have 366 days in the year, and in a ten year cycle, like your example, you'd have at minimum, two years with extra days. Perhaps using a datetime function to calculate that would be better.

  • The naming behind outputPar could be improved; outputParagraph: for example.

  • Rather than repeating outputPar.appendChild() over and over, move it to an array, and do it in a loop:

  • You could consider placeholder attributes 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)

  • parseFloat(daysElapsed / 365).toFixed(2): Note that leap years have 366 days in the year, and in a ten year cycle, like your example, you'd have at minimum, two years with extra days. Perhaps using a datetime function to calculate that would be better.

  • The naming behind outputPar could be improved; outputParagraph: for example.

  • Rather than repeating outputPar.appendChild() over and over, move it to an array, and do it in a loop:

  • You could consider placeholder attributes 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)

  • The naming behind outputPar could be improved; outputParagraph: for example.

  • Rather than repeating outputPar.appendChild() over and over, move it to an array, and do it in a loop:

Source Link
Quill
  • 12.1k
  • 5
  • 41
  • 94
Loading