Standard functions (JavaScript)

Standard functions

> Tutorial

A function is used to perform a task such as a calculation or an action. It takes arguments as input, executes instructions and can return a result.

In our current code, we use the following functions and methods:

The documentation

Leek Wars provides hundreds of functions and methods, grouped together on one page: the documentation. To access it, go to the Help tab, then click on Documentation.

It is possible to open the documentation from any page with the shortcut Ctrl + Alt + H. Try it now!

The description of a function provides you with the following information:

Using chips

Now that we are familiar with functions, we are going to use a little more in our AI!

A Chip is a battle-ready power that can be used to heal, protect, boost, attack, and more. To use it, you must first equip it on your leek:

Then, use the me.useChip(chip) method to launch a chip. Unlike weapons, there is no need to equip them first.

Purchase the Bandage, Motivation, Protein and Helmet chips and equip them on your leek.

We will use them all at the start of our turn, adding the following code after equipping our weapon:

Chip.motivation, Chip.protein are, like Weapon.pistol, predefined values representing the chip or the weapon that we want to use. They are listed in the documentation like functions.

❓ Quiz

What can a function do?

Calculate and return a value Perform an action or instructions Not return a value Take multiple parameters

Full AI