Copy link to clipboard
Copied
Need some clue on what it means. Trying to translate a number between 10 and 99 into its word. Here is my code and the confusion pointed out.
// Name:
// Date:
// 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
lblOutput.text = onesDigit.toString();
}
// This is the ones function
// It outputs the word representaion for any number from 1 - 9 inclusive
function ones()
{
// write the code here
lblOutput.text = tensDigit.toString() + onesDigit.toString();
}
// This is the teens function
// It outputs the word representation for any number from 10 - 19 inclusive
function teens() <-----------------------------------------------------------------------Over here
{
// write the code here
lblOutput.text = teens();
}
// 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 = "";
}
Have something to add?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now