Advertisement
BOT_Yokel

ICS3U1 Unit 1 Activity 4: Question 1

Jul 11th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This line makes the button, btnCalculate wait for a mouse click
  2. // When the button is clicked, the displayCoins function is called
  3. btnCalculate.addEventListener(MouseEvent.CLICK, displayCoins);
  4.  
  5. // This line makes the textinput, txtinRadius wait for a mouse click
  6. // When the textinput is clicked, the clearLabels function is called
  7. txtinAmount.addEventListener(MouseEvent.CLICK, clearLabels);
  8.  
  9. // This is the displayCoins function
  10. // e:MouseEvent is the click event experienced by the button
  11. // void indicates that the function does not return a value
  12. function displayCoins(e:MouseEvent):void
  13. {
  14.  
  15.     // declare the variables
  16.     var Initial:Number;
  17.     var Quarters:Number;
  18.     var Dimes:Number;
  19.     var Nickels:Number;
  20.     var Pennies:Number;
  21.     var Remainder1:Number;
  22.     var Remainder2:Number;
  23.     var Remainder3:Number;
  24.  
  25.     // calculate the debt burden per year
  26.     Initial = Number(txtinAmount.text)
  27.     Remainder1 = Initial % 25
  28.     Quarters = (Initial - Remainder1) / 25
  29.     Remainder2 = Remainder1 % 10
  30.     Dimes = (Remainder1 - Remainder2) / 10
  31.     Remainder3 = Remainder2 % 5
  32.     Nickels = (Remainder2 - Remainder3) / 5
  33.     Pennies = Remainder3 / 1
  34.  
  35.     // put the values into the labels
  36.     lblQuarters.text = Quarters.toFixed(0);
  37.     lblDimes.text = Dimes.toFixed(0);
  38.     lblNickels.text = Nickels.toFixed(0);
  39.     lblPennies.text = Pennies.toFixed(0);
  40. }
  41.  
  42. // This is the clearLabels 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 clearLabels(e:MouseEvent):void
  46. {
  47. txtinAmount.text = "";
  48. lblQuarters.text = "";
  49. lblDimes.text = "";
  50. lblNickels.text = "";
  51. lblPennies.text = "";
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement