# Worked Examples

The Javascript engine in PinballY is pretty powerful, but as with most programming tools, it can have a bit of a learning curve. I've tried to make it approachable for people who already know their way around Javascript, but there's still a lot of new information to take in because of the breadth of the interface between Javascript and PinballY.

To help you get started, this section contains some worked examples. I think most people find it easiest to learn new programming tasks by example, so hopefully this will ease the learning curve a bit. At the very least, it might give you a feel for the sorts of things you can do with Javascript and some pointers for where to start. I've tried to choose tasks that aren't just contrived exercises, but do things that might actually be useful. In fact, most are based on actual use cases that came up talking to people using the program. I've also tried to flesh out the examples enough to be usable as presented.

If you're new to Javascript itself, you might want to spend a little time with a Javascript tutorial before diving into the examples, so that the basic syntax makes sense. These examples are designed more to illustrate how to use PinballY features than as examples of Javascript coding techniques, since there are already so many good Javascript tutorials available online.

Here are the examples:

## How to use the examples on your system

When PinballY starts up, it looks for a file in the PinballY Scripts folder called Main.js. If that file exists, PinballY enables Javascript, reads the file, and executes the program code it contains. You can read more about this in the main Javascript Scripting help section.

To use any of the examples, then, you could simply copy and paste the code sections you want to use into Main.js. However, I'd recommend a different approach. Rather than putting everything in that single file Main.js, I'd use a separate file for each "feature", and then use the Javascript import() command to load each file from Main.js. By "feature", I just mean a body of related Javascript code that works as a unit. Keeping each feature in its own separate file will make it easier to keep track of which code does what.

For example, to add a Top 10 Filter to your system:

- Copy the desired code from the Top 10 Filter chapter to a new file in your PinballY Scripts folder - let's call it TopGames.js
- In Main.js, add this code: import("TopGames.js");