let b = 2;
β
console.log(a + b); // Addition: 7
console.log(a  b); // Subtraction: 3
console.log(a * b); // Multiplication: 10
console.log(a / b); // Division: 2.5
console.log(a % b); // Modulus (remainder): 1
console.log(a ** b); // Exponentiation: 25
The Math
object provides several properties and methods for mathematical constants and functions.
Math.PI
: Returns the value of Ο (3.14159...)Math.E
: Returns the value of Euler's number (e)console.log(Math.PI); // 3.141592653589793
console.log(Math.E); // 2.718281828459045
Math.round()
: Rounds to the nearest integerMath.ceil()
: Rounds up to the next largest integerMath.floor()
: Rounds down to the next smallest integerMath.trunc()
: Truncates the decimal partlet num = 5.7;
β
console.log(Math.round(num)); // 6
console.log(Math.ceil(num)); // 6
console.log(Math.floor(num)); // 5
console.log(Math.trunc(num)); // 5
Math.random()
: Returns a random number between 0 (inclusive) and 1 (exclusive)console.log(Math.random()); // e.g., 0.4971539834831
To get a random number between a specified range:
\nfunctiongetRandomInt(min, max) {
returnMath.floor(Math.random() * (max  min + 1)) + min;
}
β
console.log(getRandomInt(1, 10)); // Random integer between 1 and 10
Math.abs()
: Returns the absolute value of a numberconsole.log(Math.abs(5)); // 5
Math.sin()
, Math.cos()
, Math.tan()
: Sine, cosine, and tangent functions (arguments in radians)Math.asin()
, Math.acos()
, Math.atan()
: Inverse trigonometric functionsconsole.log(Math.sin(Math.PI / 2)); // 1
console.log(Math.cos(0)); // 1
console.log(Math.tan(Math.PI / 4)); // 1
Math.sqrt()
: Square rootMath.pow()
: PowerMath.exp()
: Exponential function (e^x)Math.log()
: Natural logarithm (base e)Math.max()
, Math.min()
: Maximum and minimum values from a list of numbersconsole.log(Math.sqrt(25)); // 5
console.log(Math.pow(2, 3)); // 8
console.log(Math.exp(1)); // 2.718281828459045 (approximation of e)
console.log(Math.log(Math.E)); // 1
console.log(Math.max(1, 5, 3)); // 5
console.log(Math.min(1, 5, 3)); // 1
This should give you a good starting point for working with math in JavaScript! If you have any specific questions or need more details, feel free to ask.
\nβ
\nLet's hear it for @jeffamcavoy again!
\n

β
\nAlso thanks for including us in this AI tools rundown βheyanirudhgoelβ! Check out the other tools to supercharge your workflow.
\n

β
\nβ
\nHappy coding!
\nπ€ the Slater Team
\nβ
\nIf Slater helps you create better websites, please support the team behind it.
\nBecome a Pro Slater User 
β β β We're back from a companywide summer pause (or winter pause for our Southern Hemisphere team members). Edgar Allan is hitting it's numbers! β Let's look at some new Community Library scripts: β π Dynamically loads HTML content based on a random number. This is a quick script we wrote to give a dynamic intro into a soontobereleased https://edgarallan.com. βhttps://slater.app/community_library/randomcontentaee7f7f23ab84e6f887eea54cad0ebbfβ From Jared Malanββ β βοΈ Create a variable for your state machine inputs by input name. This script comes in from @jeffamcavoy who is launching a Rive Animation course. Check it out if you want to add more movement to your Webflow project. From jeffamcavoyβ β π Smooth scrolling setup using Lenis library with scroll event logging. @SarkisBuniatyan posted a simple way to add Lenis to your Webflow project. The only faster wayone that gives you full controlis to grab this script and add it to your active Slater project. βhttps://slater.app/community_library/lenissmoothscrolling352b7c92921d44e8a051c462dd64043dβ From Jared Malanββ β Javascript 101: Javascript MathLet's build off of the random dynamic loading script highlighted at the beginning of this email. To create that experience, we needed to generate a random number. Luckily this is fairly trivial because of Javascript's builtin math capabilities. Some of the Math functions are super useful (e.g. random numbers, rounding) for even the most basic Javascript developers. Others will only be used by the most seasoned. Basic ArithmeticYou can use the standard arithmetic operators for basic calculations:
Math ObjectThe Constants
Rounding Functions
Random Numbers
To get a random number between a specified range:
Absolute Value
Trigonometric Functions
Other Useful Functions
This should give you a good starting point for working with math in JavaScript! If you have any specific questions or need more details, feel free to ask. β Your projects, supported by SlaterLet's hear it for @jeffamcavoy again!
β Also thanks for including us in this AI tools rundown βheyanirudhgoelβ! Check out the other tools to supercharge your workflow.
β β Happy coding! π€ the Slater Team β If Slater helps you create better websites, please support the team behind it.

Slater resources, updates and community activity
Have you built a Webflow project with WF Localization? Is it working for you? Slater support for WF Localization has been a common request, so we now support it. If you have a Webflow project with Localization, give it a try. Next, we are exploring how to support code sharing across files. Currently, we are binding functions to the window object, but that solution has some downsides. With the work we are doing on the next version of edgarallan.com, function sharing across files is becoming...
Are you using Webflow localization? We've received several requests to provide better support for it, so we're working on an update. I just finished writing the code. We need to do some testing before releasing the update early next week. Community library scripts β―οΈ Pause/Reset Video Embed on Click Stops all iframe videos by resetting their source on '.closevideo' button click. From Corey Moen. β° Progress Bar TimerJavaScript code to dynamically update a progress bar based on time between...
The AI world moves fast, and we are keeping up. This week, OpenAI released a new model, GPT 4.o mini. GPT 4.0 mini is an improved, costeffective model that we are supporting under Slater's free tier. The default Slater AI will continue to be powered by GPT 3.5 as we test GPT 4.0 mini, but you can configure GPT 4.0 mini or even GPT 4.0 (paid) today. Community library scripts π Fix Paragraph Runts With Nonbreaking SpacePrevent singleword runts in HTML elements with the class `.norunt`. From...