BOT_Yokel

ICS3U1 Unit 2 Activity 2: Question 2

Jul 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date: July 19, 2017
  2. // Purpose: To convert any number from 10 - 99 to its word representation
  3.  
  4. // This line makes the button, btnConvert wait for a mouse click
  5. // When the button is clicked, the convertNumber function is called
  6. btnConvert.addEventListener(MouseEvent.CLICK, convertNumber);
  7.  
  8. // These lines make the textinputs wait for a mouse click
  9. // When any of these components are clicked, the clearLabels function is called
  10. txtinNumber.addEventListener(MouseEvent.CLICK, clearLabels);
  11.  
  12. // Declare Global Variables
  13. var num:int;         // number from 10 - 99
  14. var tensDigit:int;   // the tens digit
  15. var onesDigit:int;   // the ones digit
  16.    
  17. // This is the convertNumber function
  18. // e:MouseEvent is the click event experienced by the button
  19. // void indicates that the function does not return a value
  20. function convertNumber(e:MouseEvent):void
  21. {
  22.     getData();
  23.     if (num < 10 || num > 99){
  24.         lblOutput.text = "Invalid number. Enter a number between 10 and 99 inclusive.";
  25.     }
  26.     else{
  27.         lblOutput.text = "";
  28.         if (num >= 20) {
  29.             tensDigit = Math.floor(num / 10);
  30.             onesDigit = num % 10;
  31.             tens();
  32.             ones();
  33.         }
  34.         else{
  35.             tensDigit = Math.floor(num / 10);
  36.             onesDigit = num % 10;
  37.             teens();
  38.         }
  39.     }
  40. }
  41.  
  42. // This is the getData function
  43. // It gets the number from the user
  44. function getData()
  45. {
  46.     // complete the code here
  47.     num = int(txtinNumber.text);
  48. }
  49.  
  50. // This is the tens function
  51. // It outputs the word representation of 20, 30, 40,..,90
  52. function tens()
  53. {
  54.     //write the code here
  55.     if (tensDigit == 2)
  56.     {
  57.         lblOutput.text = "Twenty ";
  58.     }
  59.    
  60.     else if (tensDigit == 3)
  61.     {
  62.         lblOutput.text = "Thirty ";
  63.     }
  64.    
  65.     else if (tensDigit == 4)
  66.     {
  67.         lblOutput.text = "Forty ";
  68.     }
  69.    
  70.     else if (tensDigit == 5)
  71.     {
  72.         lblOutput.text = "Fifty ";
  73.     }
  74.    
  75.     else if (tensDigit == 6)
  76.     {
  77.         lblOutput.text = "Sixty ";
  78.     }
  79.    
  80.     else if (tensDigit == 7)
  81.     {
  82.         lblOutput.text = "Seventy ";
  83.     }
  84.    
  85.     else if (tensDigit == 8)
  86.     {
  87.         lblOutput.text = "Eighty ";
  88.     }
  89.    
  90.     else if (tensDigit == 9)
  91.     {
  92.         lblOutput.text = "Ninety ";
  93.     }
  94.    
  95. }
  96.  
  97. // This is the ones function
  98. // It outputs the word representaion for any number from 1 - 9 inclusive
  99. function ones()
  100. {
  101.     // write the code here
  102.     if (onesDigit == 1)
  103.     {
  104.         lblOutput.text += "One";
  105.     }
  106.    
  107.     else if (onesDigit == 2)
  108.     {
  109.         lblOutput.text += "Two";
  110.     }
  111.    
  112.     else if (onesDigit == 3)
  113.     {
  114.         lblOutput.text += "Three";
  115.     }
  116.    
  117.     else if (onesDigit == 4)
  118.     {
  119.         lblOutput.text += "Four";
  120.     }
  121.    
  122.     else if (onesDigit == 5)
  123.     {
  124.         lblOutput.text += "Five";
  125.     }
  126.    
  127.     else if (onesDigit == 6)
  128.     {
  129.         lblOutput.text += "Six";
  130.     }
  131.    
  132.     else if (onesDigit == 7)
  133.     {
  134.         lblOutput.text += "Seven";
  135.     }
  136.    
  137.     else if (onesDigit == 8)
  138.     {
  139.         lblOutput.text += "Eight";
  140.     }
  141.    
  142.     else if (onesDigit == 9)
  143.     {
  144.         lblOutput.text += "Nine";
  145.     }
  146. }
  147.  
  148. // This is the teens function
  149. // It outputs the word representation for any number from 10 - 19 inclusive
  150. function teens()
  151. {
  152.     // write the code here
  153.     if (onesDigit == 0)
  154.     {
  155.         lblOutput.text = "Ten";
  156.     }
  157.    
  158.     if (onesDigit == 1)
  159.     {
  160.         lblOutput.text = "Eleven";
  161.     }
  162.    
  163.     else if (onesDigit == 2)
  164.     {
  165.         lblOutput.text = "Twelve";
  166.     }
  167.    
  168.     else if (onesDigit == 3)
  169.     {
  170.         lblOutput.text = "Thirteen";
  171.     }
  172.    
  173.     else if (onesDigit == 4)
  174.     {
  175.         lblOutput.text = "Fourteen";
  176.     }
  177.    
  178.     else if (onesDigit == 5)
  179.     {
  180.         lblOutput.text = "Fifteen";
  181.     }
  182.    
  183.     else if (onesDigit == 6)
  184.     {
  185.         lblOutput.text = "Sixteen";
  186.     }
  187.    
  188.     else if (onesDigit == 7)
  189.     {
  190.         lblOutput.text = "Seventeen";
  191.     }
  192.    
  193.     else if (onesDigit == 8)
  194.     {
  195.         lblOutput.text = "Eighteen";
  196.     }
  197.    
  198.     else if (onesDigit == 9)
  199.     {
  200.         lblOutput.text = "Nineteen";
  201.     }
  202. }
  203.  
  204. // This is the clearLabels function
  205. // e:MouseEvent is the click event experienced by the textInput
  206. // void indicates that the function does not return a value
  207. function clearLabels(e:MouseEvent):void
  208. {
  209.      lblOutput.text = "";
  210. }
Add Comment
Please, Sign In to add comment