Advertisement
BOT_Yokel

ICS3U1 Unit 2 Activity 1: Question 1

Jul 18th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date Completed: July 18, 2017
  2. // Purpose: Counting the number of vowels in a sentence.
  3.  
  4. // This line makes the button, btnCalculate wait for a mouse click
  5. // When the button is clicked, the determineVowels function is called
  6. btnCalculate.addEventListener(MouseEvent.CLICK, determineVowels);
  7.  
  8. // This line makes the textinputs: txtinSentence wait for a mouse click
  9. // When a textinput is clicked, the clearLabel 1 function is called
  10. txtinSentence.addEventListener(MouseEvent.CLICK, clearLabel1);
  11.  
  12. // This is the determineVowels function
  13. // e:MouseEvent is the click event experienced by the button
  14. // void indicates that the function does not return a value
  15. function determineVowels(e:MouseEvent):void
  16. {
  17.  
  18.   // Declare the variables
  19.   var Origin:String;
  20.   var Count:Number = 0;
  21.   var Consistent:String;
  22.  
  23.   //Declare the value of the Origin
  24.   Origin = String(txtinSentence.text)
  25.   Consistent = Origin.toLowerCase(); // Convert the string to upppercase for easier detection
  26.  
  27.   // Introduce a loop through the Consistent
  28.   for (var i = 0; i <= Consistent.length - 1; i++)
  29.  {
  30.   //If character is found to be a vowel, add 1 to current vowel count
  31.     if (Consistent.charAt(i) == "a" || Consistent.charAt(i) == "e" || Consistent.charAt(i) == "i" || Consistent.charAt(i) == "o" || Consistent.charAt(i) == "u")
  32.     {
  33.       Count += 1;
  34.     }
  35.    
  36.   }
  37.  
  38.   lblResult.text = "There are " + Count + " vowels in the sentence.";
  39.  
  40.  }
  41.  
  42. // This is the clearLabel1 function
  43. // e:MouseEvent is the click event experienced by the textinput
  44. // void indicates that the function does not return a value
  45. function clearLabel1(e:MouseEvent):void
  46.  
  47. {
  48.     lblResult.text = "";
  49.     txtinSentence.text = "";
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement