Search code examples
javascriptinternet-explorercross-browserisinteger

isIntegar polyfill fix on IE11


I have some JavaScript that uses isIntegar, I understand I need to add polyfill but am confused on how to do this with my code.

IE dose not currently like my code

My code

 if (!Number.isInteger(averageRatingResult)) {
            for (var j = 0; j < averageRatingResult; j++) {
                if (averageRatingResult - j < 1) {
                    averageRating += '<i class="fa fa-star-half rating-stars" aria-hidden="true"></i>';
                }
                else {
                    averageRating += '<i class="fa fa-star rating-stars" aria-hidden="true"></i>';
                }
            }
        }
        else {
            for (var j = 0; j < averageRatingResult; j++) {
                averageRating += '<i class="fa fa-star rating-stars" aria-hidden="true"></i></span>';
            }
        }

Error I am getting

SCRIPT438: Object doesn't support property or method 'isInteger' ratingswigetcontent.js (21,9)


Solution

  • Maybe something simpler like this will do

    if (averageRatingResult === parseInt(averageRatingResult, 10))
    

    Depends more on what your potential value it can be