Calculating user birth information Can you please check if I've written the code correctly?

The task was:


Calculate the user's month of birth as a a number, where January = 0 through to December = 11. 
Take the string entered 
Get the substring, being the first three characters 
Convert to uppercase 
Find the starting location of the three-letter abbreviation in the month abbreviations string, and divide this by 3 (this is not the only way to find the month number, but it allows us to practice searching in a string)




var year = prompt('Enter year of birth as a 4 digit integer');      

var month = prompt('Enter the name of the month of birth');

// Chop everything after the first 3 characters and make it uppercase
month = month.substring(0,3).toUpperCase();

// Store your array in months, differently named than the month input
var months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT",         
"NOV", "DEC"];

// We then use array.indexOf() to locate it in the array
var pos = months.indexOf(month);
if (pos &gt;= 0) {
// valid month, number is pos
}

var date = prompt('Enter day of birth as an integer');
Everything looks good. 

That said, array.indexOf wasn't supported in Internet Explorer until version 9.

If you need that support, the Mozilla Developer Network has a handy function you can include in your code to provide support for those browsers:

if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
        "use strict";
        if (this == null) {
            throw new TypeError();
        }
        var t = Object(this);
        var len = t.length &gt;&gt;&gt; 0;
        if (len === 0) {
            return -1;
        }
        var n = 0;
        if (arguments.length &gt; 0) {
            n = Number(arguments[1]);
            if (n != n) { // shortcut for verifying if it's NaN
                n = 0;
            } else if (n != 0 &amp;&amp; n != Infinity &amp;&amp; n != -Infinity) {
                n = (n &gt; 0 || -1) * Math.floor(Math.abs(n));
            }
        }
        if (n &gt;= len) {
            return -1;
        }
        var k = n &gt;= 0 ? n : Math.max(len - Math.abs(n), 0);
        for (; k &lt; len; k++) {
            if (k in t &amp;&amp; t[k] === searchElement) {
                return k;
            }
        }
        return -1;
    }
}