πŸ€” Math?


​

​

​

We're back from a company-wide 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 soon-to-be-released https://edgarallan.com.

​https://slater.app/community_library/random-content-aee7f7f2-3ab8-4e6f-887e-ea54cad0ebbf​

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.

​https://slater.app/community_library/rive-input-create-variable-by-name-f49bb354-7684-4dc9-8b9a-68860ce31b41​

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 way--one that gives you full control--is to grab this script and add it to your active Slater project.

​https://slater.app/community_library/lenis-smooth-scrolling-352b7c92-921d-44e8-a051-c462dd64043d​

From Jared Malan​​

​

Javascript 101: Javascript Math

Let'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 built-in 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 Arithmetic

You can use the standard arithmetic operators for basic calculations:

let a = 5;
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

Math Object

The Math object provides several properties and methods for mathematical constants and functions.

Constants

  • 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

Rounding Functions

  • Math.round(): Rounds to the nearest integer
  • Math.ceil(): Rounds up to the next largest integer
  • Math.floor(): Rounds down to the next smallest integer
  • Math.trunc(): Truncates the decimal part

let 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

Random Numbers

  • 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:

functiongetRandomInt(min, max) {
returnMath.floor(Math.random() * (max - min + 1)) + min;
}
​
console.log(getRandomInt(1, 10)); // Random integer between 1 and 10

Absolute Value

  • Math.abs(): Returns the absolute value of a number

console.log(Math.abs(-5)); // 5

Trigonometric Functions

  • Math.sin(), Math.cos(), Math.tan(): Sine, cosine, and tangent functions (arguments in radians)
  • Math.asin(), Math.acos(), Math.atan(): Inverse trigonometric functions

console.log(Math.sin(Math.PI / 2)); // 1
console.log(Math.cos(0)); // 1
console.log(Math.tan(Math.PI / 4)); // 1

Other Useful Functions

  • Math.sqrt(): Square root
  • Math.pow(): Power
  • Math.exp(): Exponential function (e^x)
  • Math.log(): Natural logarithm (base e)
  • Math.max(), Math.min(): Maximum and minimum values from a list of numbers

console.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.

​

Your projects, supported by Slater

Let'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.

twitter profile avatar
Anirudh Goel
Twitter Logo
@heyanirudhgoel
@relume_io 2.) https://slater.app/ - Slater β€” a code editor that harnesses the power of AI so you can take your projects to the next level. @Slater_App
photo
twitter profile avatar
Anirudh Goel
@heyanirudhgoel
1.) https://www.relume.io/ - Describe the company in sentence or two and get the full wire frame @relume_io
12:55 AM β€’ Jul 10, 2024
0
Retweets
2
Likes
​

​

​

Happy coding!

πŸ€™ the Slater Team

​

If Slater helps you create better websites, please support the team behind it.

Welcome To Slater!

Slater resources, updates and community activity

Read more from Welcome To Slater!
video

You may recall that the original Slater had access controls for projects and files. We didn't want just anyone going in there and rewriting our Javascript. However, managing access for teammates became cumbersome (I even added a "god mode" to give myself access to any project or file). Since we generally trusted each other and never had issues, we decided to leave it out of the latest version of Slater. That said, we understand that some teams work differently, and maintaining control can be...

video

We're going to take a brief break from the regular newsletter format to celebrate the release of ask.edgarallan.com. Today, let's hear from Mason Poe, the Founder of Edgar Allan and Slater. I'm thrilled to announce the launch of ask.edgarallan.com and the start of a new conversation. We can all feel it: the web is changing in ways that seem both dramatic and, in a weird way, imperceptible. At times, it’s hard to know where to start exploring what could be next. Sometimes, when you think...

Our new Edgar Allan website, which we're launching next week 🀫, uses over 3,000 lines of code. It’s a bit unwieldy! To better support the new EA website and similar JavaScript-heavy projects, we’ve added slater_import. This feature allows you to write a function once and then reuse it across all the files in your project. You can see how to use it here. ⬇️ Not ready to watch the video? No problem. To import a file, simply start typing the name of the file you want to import and click on the...