/ Published in: ActionScript 3
This snippet is used for the blog post called Arithmetic Operators in Flash and ActionScript 3.0, which can be found at http://www.brettwidmann.com/2010/10/arithmetic-operators-in-flashactionscript-3-0 which is set to publish on November 1, 2010.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* Each trace function demonstrates the type of Arithmetic operators in Flash. Commented out trace() functions demonstrate an easier to read example while the verbose versions represent cleaner formatting in the console.*/ //Addition trace("The sum of 15 + 6 is: " + (15 + 6)); //trace(15 + 6); trace("\n"); //Subtraction trace("The difference of 15 and 6 is: " + (15 - 6) ); //trace(15 - 6); trace("\n"); //Multiplication trace("The product of 15 and 6 is: " + (15 * 6)); //trace(15 * 6); trace("\n"); //Division trace("The quotient of 15 and 6 is: " + (15 / 6)); //trace(15 / 6); trace("\n"); //Modulo trace("The modulus (remainder) of 15 and 6 is: " + (15 % 6)); //trace(15 % 6); trace("\n"); //Order of Operations Example 1 trace("Parentheticals take precedence in Arithmetic!"); trace("(4 * 2) + 6 = " + ((4 * 2) + 6)); //trace((4 * 2) + 6); trace("\n"); //Order of Operations Example 2 trace("(10 + 6) * 3 = " + ((10 + 6) * 3)); trace("\n"); //String Concatenation Example var concatSentence:String = "This is an example of " + "string concatenation."; trace(concatSentence);
URL: http://www.brettwidmann.com