View Single Post
Old 05-17-2005, 01:31 AM   #1 (permalink)
watson6
Registered User
 
Join Date: May 2005
Posts: 1
watson6 is on a distinguished road
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>
watson6 is offline   Reply With Quote