View Single Post
Old 05-17-2005, 01:31 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,505
sde is on a distinguished road
you probably want to check each letter instead of assuming the user will enter a z. try this:
HTML Code:
<script>

var letter, length, total;
total = 0;

letter = window.prompt('Please enter a letter, z to stop', '');
length = letter.length;

var my_array = letter.split("");

for(var i=0;i<length;i++){
  
  if( my_array[i] == 'a' ){
    total++;
  }
}


document.write('The number of \'a\'s you have input is ' + total)

</script>
it will only work in IE though ( i think )
__________________
Mike
sde is offline   Reply With Quote