You can use this simple code that checks the first letter of the given word and use the correct article:
function prependArticle(word){
var vowels = 'aeiou';
var firstLetter = word[0].toLowerCase();
if(vowels.indexOf(firstLetter) > -1)
return 'An ' + word;
else
return 'A ' + word;
}
//Test the function:
document.write(prependArticle('Book') + '<br/>');
document.write(prependArticle('App') + '<br/>');
document.write(prependArticle('eBook') + '<br/>');
document.write(prependArticle('Record') + '<br/>');
However, that's not perfect. For instance the word "Unicorn" starts with "U", yet it should prepended with "A", not "An". Similarly, the word "Hour" start with "H" yet, it should be prepended with "An", not "A". Also acronyms have some complexity because we prepend them based on how we pronounce them, not how we write them.