Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Date Completed: July 18, 2017
- // Purpose: Counting the number of vowels in a sentence.
- // This line makes the button, btnCalculate wait for a mouse click
- // When the button is clicked, the determineVowels function is called
- btnCalculate.addEventListener(MouseEvent.CLICK, determineVowels);
- // This line makes the textinputs: txtinSentence wait for a mouse click
- // When a textinput is clicked, the clearLabel 1 function is called
- txtinSentence.addEventListener(MouseEvent.CLICK, clearLabel1);
- // This is the determineVowels function
- // e:MouseEvent is the click event experienced by the button
- // void indicates that the function does not return a value
- function determineVowels(e:MouseEvent):void
- {
- // Declare the variables
- var Origin:String;
- var Count:Number = 0;
- var Consistent:String;
- //Declare the value of the Origin
- Origin = String(txtinSentence.text)
- Consistent = Origin.toLowerCase(); // Convert the string to upppercase for easier detection
- // Introduce a loop through the Consistent
- for (var i = 0; i <= Consistent.length - 1; i++)
- {
- //If character is found to be a vowel, add 1 to current vowel count
- if (Consistent.charAt(i) == "a" || Consistent.charAt(i) == "e" || Consistent.charAt(i) == "i" || Consistent.charAt(i) == "o" || Consistent.charAt(i) == "u")
- {
- Count += 1;
- }
- }
- lblResult.text = "There are " + Count + " vowels in the sentence.";
- }
- // This is the clearLabel1 function
- // e:MouseEvent is the click event experienced by the textinput
- // void indicates that the function does not return a value
- function clearLabel1(e:MouseEvent):void
- {
- lblResult.text = "";
- txtinSentence.text = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement