Below is a JavaScript function with a number of errors. Find each
error. In your written answer, number each error and briefly describe
the error.
// this function compares the user entered password (p) against the
// actual password (q). The form name is 'myform', and the text object
// name where the user enters their password is 'password'.
function checkpassword() {
var p = window.document.myform.password;
var q = "qIqn0";
var valid = "1";
if( p.length != q.length ) {
valid = 0;
} else {
for( var k=1 ; k<=p.length ; k++ ) {
if( p.charAt(k) != q.charAt(k) ) {
valid = 0;
}
}
}
if( valid = 0 ) {
window.error( "invalid password" );
return false;
}
return true;
}