Consider a simple onkeypress script that alerts with messages like
"You typed a A!"
I have written a small function that considers when it should be
"You typed an A!"
where the variable string is preceded by "an" rather than "a", and would
appreciate comments, since English is not my mother language and I
don't know exactly when you say "an" rather than "a". If I feed whole
words to this function, is a test for the first letter enough?
function atrailn(n,u){
var a = ['a','e','f','h' ,'i','l','m','n ','r','s','x',' 8','11','18','8 0' ];
if( typeof n==='string' ){ n=n.charAt(0); }
return
( u ? 'A' : 'a' ) +
( in_array( (''+n).toLowerC ase() , a ) ? 'n' : '' ) +
' ' + n;
}
function in_array(n,a){
var i=a.length; while(i--){ if(a[i]===n){ return true; } } return false;
}
function alertletter(n){
alert( 'That was ' + atrailn(n) + '.' );
}
--
Ivo
"You typed a A!"
I have written a small function that considers when it should be
"You typed an A!"
where the variable string is preceded by "an" rather than "a", and would
appreciate comments, since English is not my mother language and I
don't know exactly when you say "an" rather than "a". If I feed whole
words to this function, is a test for the first letter enough?
function atrailn(n,u){
var a = ['a','e','f','h' ,'i','l','m','n ','r','s','x',' 8','11','18','8 0' ];
if( typeof n==='string' ){ n=n.charAt(0); }
return
( u ? 'A' : 'a' ) +
( in_array( (''+n).toLowerC ase() , a ) ? 'n' : '' ) +
' ' + n;
}
function in_array(n,a){
var i=a.length; while(i--){ if(a[i]===n){ return true; } } return false;
}
function alertletter(n){
alert( 'That was ' + atrailn(n) + '.' );
}
--
Ivo
Comment