|
Counting letters
I am new to JavaScript and would appreciate a little help.
I have a small program to count the number of times a letter a is input. it finishes when a z is input and displays the total number of a's at the end.
This is the code i have and i am sure i am missing something very simple but cannot see it. many thanks.
<html>
<script>
var letter, total;
total = 0;
letter = window.prompt('Please enter a letter, z to
stop', '');
while (letter != 'z')
{
if (letter ='a')
{
total = total + 1
}
letter = window.prompt('Please enter a letter, z to
stop', '')
}
document.write('The number of \'a\'s you have input is
' + total)
</script>
</html>
|