Advertisement
BOT_Yokel

ICS3U1 Unit 1 Activity 6: Question 1

Jul 13th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date Completed: July 13, 2017
  2. // Purpose: Converting ounces to grams
  3.  
  4. // This line makes the button, btnConvert wait for a mouse click
  5. // When the button is clicked, the determineConversion function is called
  6. btnConvert.addEventListener(MouseEvent.CLICK, determineConversion);
  7.  
  8. // This is the determineConversion function
  9. // e:MouseEvent is the click event experienced by the button
  10. // void indicates that the function does not return a value
  11. function determineConversion(e:MouseEvent):void
  12.  
  13. {
  14.     //Declare the variables for the while statements
  15.     var Ounces:Number = 1;
  16.     var Grams:Number;
  17.    
  18.     //Introduce the while statement for converting Ounces to Grams from 1 to 15 ounces
  19.     while (Ounces <=15)
  20.     {
  21.         //Convert Grams to Ounces, add it to the Grams column with a fixed decimal point (2), add a new line, add the Ounces to the Ounces column, add a new line, add 1 to the Ounces and repeat
  22.         Grams = Ounces * 28.35
  23.         lblGrams.text += Grams.toFixed(2) + "\r"
  24.         lblOunces.text += String(Ounces) + "\r";
  25.         Ounces++;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement