// workingWithOperators.jsx // Copyright 2007 // Written by Jeffrey Tranberry // Photoshop for Geeks Version 1.0 /* Description: This script demonstates how to work with operators */ // enable double clicking from the // Macintosh Finder or the Windows Explorer #target photoshop // Make Photoshop the frontmost application // in case we double clicked the file app.bringToFront(); /////////////////////////// // MAIN // /////////////////////////// // Working with Arithmetic Operators // + (Addition) // - (Subtraction) // * (Multiplication) // / (Division) // add Numbers alert(6 + 1); // subtract numbers alert(6 - 1); // multiply numbers alert(6*2); // divide numbers alert(6/2); //creates 3 variables, in this case a 'string'. var a = '5', b = '6', c = '7'; // Use the '+' operator concatenate the // number/strings as a new string '567' alert (a+b+c); //creates 3 variables, in this case 'numeric'. var a = 5, b = 6, c = 7; // Use the '+' operator to give the value // of the added numeric values, in this case 18 alert (a+b+c); // creates 3 variables, in this case // two are 'numeric' and one is a string. var a = 5, b = 6, c = "7"; // Use the '+' operator to give the value // The first two are added to make 11 and 7 // is concatenated on the end to give 117 alert (a+b+c); // Concatenating Strings // Define some variables // In this case, use strings var me = "Jeff" var wife = "Rachel"; var dog = "The Todd"; alert(me); alert(wife); alert(dog) // Define a varialble by concatenating variables var family = me + ", " + wife + ", and " + dog; alert(family); // forcing strings to behave as numerics // sets to variables, each a string in this case because they are in quotes var one = '1'; var two = '2'; var three = '3' // result 1 concatenates the two strings, the result should be '12' alert(one + two); // result2 uses the method Number to force the strings to be interpreted as numeric values, resulting in a value of '3' alert(Number(one) + Number(two)); // Using multiplication and division operators can coerce strings to numerics // Results in a value of 6 alert(two * three); // Results in a value of 1.5 alert(three / two);