Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Date: July 19, 2017
- // Purpose: To convert any number from 10 - 99 to its word representation
- // This line makes the button, btnConvert wait for a mouse click
- // When the button is clicked, the convertNumber function is called
- btnConvert.addEventListener(MouseEvent.CLICK, convertNumber);
- // These lines make the textinputs wait for a mouse click
- // When any of these components are clicked, the clearLabels function is called
- txtinNumber.addEventListener(MouseEvent.CLICK, clearLabels);
- // Declare Global Variables
- var num:int; // number from 10 - 99
- var tensDigit:int; // the tens digit
- var onesDigit:int; // the ones digit
- // This is the convertNumber function
- // e:MouseEvent is the click event experienced by the button
- // void indicates that the function does not return a value
- function convertNumber(e:MouseEvent):void
- {
- getData();
- if (num < 10 || num > 99){
- lblOutput.text = "Invalid number. Enter a number between 10 and 99 inclusive.";
- }
- else{
- lblOutput.text = "";
- if (num >= 20) {
- tensDigit = Math.floor(num / 10);
- onesDigit = num % 10;
- tens();
- ones();
- }
- else{
- tensDigit = Math.floor(num / 10);
- onesDigit = num % 10;
- teens();
- }
- }
- }
- // This is the getData function
- // It gets the number from the user
- function getData()
- {
- // complete the code here
- num = int(txtinNumber.text);
- }
- // This is the tens function
- // It outputs the word representation of 20, 30, 40,..,90
- function tens()
- {
- //write the code here
- if (tensDigit == 2)
- {
- lblOutput.text = "Twenty ";
- }
- else if (tensDigit == 3)
- {
- lblOutput.text = "Thirty ";
- }
- else if (tensDigit == 4)
- {
- lblOutput.text = "Forty ";
- }
- else if (tensDigit == 5)
- {
- lblOutput.text = "Fifty ";
- }
- else if (tensDigit == 6)
- {
- lblOutput.text = "Sixty ";
- }
- else if (tensDigit == 7)
- {
- lblOutput.text = "Seventy ";
- }
- else if (tensDigit == 8)
- {
- lblOutput.text = "Eighty ";
- }
- else if (tensDigit == 9)
- {
- lblOutput.text = "Ninety ";
- }
- }
- // This is the ones function
- // It outputs the word representaion for any number from 1 - 9 inclusive
- function ones()
- {
- // write the code here
- if (onesDigit == 1)
- {
- lblOutput.text += "One";
- }
- else if (onesDigit == 2)
- {
- lblOutput.text += "Two";
- }
- else if (onesDigit == 3)
- {
- lblOutput.text += "Three";
- }
- else if (onesDigit == 4)
- {
- lblOutput.text += "Four";
- }
- else if (onesDigit == 5)
- {
- lblOutput.text += "Five";
- }
- else if (onesDigit == 6)
- {
- lblOutput.text += "Six";
- }
- else if (onesDigit == 7)
- {
- lblOutput.text += "Seven";
- }
- else if (onesDigit == 8)
- {
- lblOutput.text += "Eight";
- }
- else if (onesDigit == 9)
- {
- lblOutput.text += "Nine";
- }
- }
- // This is the teens function
- // It outputs the word representation for any number from 10 - 19 inclusive
- function teens()
- {
- // write the code here
- if (onesDigit == 0)
- {
- lblOutput.text = "Ten";
- }
- if (onesDigit == 1)
- {
- lblOutput.text = "Eleven";
- }
- else if (onesDigit == 2)
- {
- lblOutput.text = "Twelve";
- }
- else if (onesDigit == 3)
- {
- lblOutput.text = "Thirteen";
- }
- else if (onesDigit == 4)
- {
- lblOutput.text = "Fourteen";
- }
- else if (onesDigit == 5)
- {
- lblOutput.text = "Fifteen";
- }
- else if (onesDigit == 6)
- {
- lblOutput.text = "Sixteen";
- }
- else if (onesDigit == 7)
- {
- lblOutput.text = "Seventeen";
- }
- else if (onesDigit == 8)
- {
- lblOutput.text = "Eighteen";
- }
- else if (onesDigit == 9)
- {
- lblOutput.text = "Nineteen";
- }
- }
- // This is the clearLabels function
- // e:MouseEvent is the click event experienced by the textInput
- // void indicates that the function does not return a value
- function clearLabels(e:MouseEvent):void
- {
- lblOutput.text = "";
- }
Add Comment
Please, Sign In to add comment