I am getting a undefined error! ActionScript3.0
I am counting the number of vowels from a word typed in the program. However am getting a undefined error for the variable totalcount which I identified. I will point out where the error is labeled down below.
// Purpose: To count the number of vowels in a sentence
// This line makes the button, btnCount wait for a mouse click
// When the button is clicked, the countvowels function is called
btnCount.addEventListener(MouseEvent.CLICK, countVowels);
// This is the countVowels function
// e:MouseEvent is the click event experienced by the button
// void indicates that the function does not return a value
function countVowels(e:MouseEvent):void
{
//declare the variables
var word:String; // number that will represent each letter
var totalcount:int = 0;
var i:Number;
var numberofvowels:String; //
var stringvalue:String;
// get the sentence from the user
word = txtinWord.text;
// count the vowels in the word
//lblVowels.text = numberofvowels.charAt(i) + "\r";
for(i = 0; i <= numberofvowels.length; i++)
{
stringvalue = word.charAt(i);
//lblVowels.text += stringvalue = "/r"
//word.charAt(i) + " " + String(i) + "\r";
if ((stringvalue == "A") || (stringvalue == "a"))
{
totalcount = totalcount + 1;
}
if((stringvalue == "O") || (stringvalue == "o"))
{
totalcount = totalcount + 1;
}
if((stringvalue == "E") || (stringvalue == "e"))
{
totalcount = totalcount + 1;
}
if((stringvalue == "I") || (stringvalue == "i"))
{
totalcount = totalcount + 1;
}
if((stringvalue == "U") || (stringvalue == "u"))
{
totalcount = totalcount + 1;
}
}
}
lblVowels.text = "There are " + String(totalcount) + " vowels in this sentence."; <----------Over here, I used function String() for total count
here is the program
