By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,623 Members | 2,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,623 IT Pros & Developers. It's quick & easy.

An N or not a N

P: n/a
Ivo
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','1 1','18','80' ];
if( typeof n==='string' ){ n=n.charAt(0); }
return
( u ? 'A' : 'a' ) +
( in_array( (''+n).toLowerCase() , 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

Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Ivo wrote:
[snip]
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?

[snip]

Not really a JavaScript question, perhaps you should try
microsoft.public.word.spelling.grammar. Anyhow, here is a
site that gives some pointers:

http://owl.english.purdue.edu/handouts/esl/eslart.html

It is a US institution (Purdue), however it should be OK.
The main thing is that it is the *sound* that is important,
not the actual letter.

e.g. 1. Some people may say "an historical perspective",
others "a historical perspective". H is not a vowel, but it
sounds like one in the above context so many people say "an"
rather than "a".

e.g. 2. "one" starts with a vowel, but most would say "a one
hundred percent chance", not "an one hundred..." because
"one" sounds like it starts with a consonant (i.e."w" as in
won) so it gets "a" not "an".

As you have noticed, you will have to convert number to
words, then test the words. But there are many exceptions
and many more examples I'm sure.

Cheers, Fred
Jul 23 '05 #2

P: n/a
On 29/9/04 8:34 pm, Ivo wrote:
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".
Use "an" for A, E, F, H, I, L, M, N, O, R, S and X. Use "a" for all the
other letters of the alphabet. (Yes, that includes "u"!)
If I feed whole
words to this function, is a test for the first letter enough?


No. This is actually very difficult to do. Take a look at:
<http://www.faqts.com/knowledge_base/entry/edit/index.phtml?aid=26340>

Phil

--
Philip Ronan
ph***********@virgin.net
(Please remove the "z"s if replying by email)
Jul 23 '05 #3

P: n/a
Philip Ronan wrote:
On 29/9/04 8:34 pm, Ivo wrote:

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

Use "an" for A, E, F, H, I, L, M, N, O, R, S and X. Use "a" for all the
other letters of the alphabet. (Yes, that includes "u"!)


Not sure where you got those rules from, but of the 13 you list, I know
at least 10 do not fit the rule you provide.

H is an exception to the consonant rule. If a word begins with a
consonant, then it uses "a", not "an". X or maybe Q would be an exception.

The difficulty comes with words that begin with a vowel (including
sometimes Y), where its not spelling determined, but phonetically
determined.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #4

P: n/a
Lee
Philip Ronan said:

On 29/9/04 8:34 pm, Ivo wrote:
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".


Use "an" for A, E, F, H, I, L, M, N, O, R, S and X. Use "a" for all the
other letters of the alphabet. (Yes, that includes "u"!)


In US English:

An hour
A hair

An onion
A one-horse town

An uncle
A union

An x-ray
A xylophone

An yttrium atom (the only example I can think of for "an y*".
A yak

I can't think of any examples of:

an F*
an L*
an M*
an N*
an R*
an S*

other than when saying the names of the letters, as in:
"Gimme an 'F'!"

Jul 23 '05 #5

P: n/a
On 30/9/04 6:07 pm, Randy Webb wrote:
Philip Ronan wrote:
On 29/9/04 8:34 pm, Ivo wrote:

Use "an" for A, E, F, H, I, L, M, N, O, R, S and X. Use "a" for all the
other letters of the alphabet. (Yes, that includes "u"!)


Not sure where you got those rules from, but of the 13 you list, I know
at least 10 do not fit the rule you provide.


I was referring to the individual letters, not words that *begin* with those
letters (which is what the OP was referring to in the text I originally
quoted).

I also gave the URL of a web page that explains the problems of applying
this to whole words (which is what the OP was referring to in the second bit
of text I originally quoted).

Here's another URL for you: <http://www.sniffles.ca/wavs/raspberry.wav> :-P

--
Philip Ronan
ph***********@virgin.net
(Please remove the "z"s if replying by email)
Jul 23 '05 #6

P: n/a
Lee wrote:

other than when saying the names of the letters, as in:
"Gimme an 'F'!"


That's exactly what Phil meant, because that is what the OP
asked for. He asked how to tell whether to put "a" or "an"
in front of single letters. Then the OP asked if this same
rule applies to words.

Phil's answer is correct on both counts.

Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.