Custom Functions
Learn how to define your own functions using `kaj` and `ferotDao` in BornomalaScript.
Custom Functions
Custom functions are functions that you write yourself.
They let you package reusable logic into one named block so you can call it whenever you need it.
Basic Example
Define and call:
kaj jogKoro(num1, num2) {
ferotDao num1 + num2
}
dhoro jogFol = jogKoro(5, 10)
lekho(jogFol)
kaj AmarKaj(x) {
lekho(x)
}
AmarKaj("ami na korle ke korbe")
This example shows two custom functions:
jogKoroadds two numbers and returns the resultAmarKajprints the value it receives
How It Works
The first function uses ferotDao to send a value back to the caller.
The second function does not return anything. It simply performs an action.
That means custom functions can either:
- return a result
- perform a task
- do both, depending on the program design
Step-by-Step Breakdown
- Define the function with
kaj - Choose the parameter names
- Put the logic inside the function body
- Use
ferotDaoif you want to send a result back - Call the function by name when you need it
Why Custom Functions Matter
Custom functions help you:
- reuse logic
- keep code organized
- reduce repetition
- make larger programs easier to understand
Try These Variations
Practice with more small functions:
kaj BoroKoro(x) {
ferotDao x * 2
}
lekho(BoroKoro(5))
kaj Shagotom(name) {
lekho("Shagotom, " + name)
}
Shagotom("Amina")
kaj Jomma(a, b) {
ferotDao a + b
}
dhoro result = Jomma(10, 20)
lekho(result)
Common Mistakes
Beginners often make these mistakes:
- forgetting to call the function after defining it
- passing the wrong number of arguments
- forgetting
ferotDaowhen a result is needed - using unclear parameter names
Practice Task
Try writing custom functions that:
- greet a person by name
- add two numbers
- print a message using an argument
Quick Checklist
Before moving on, make sure you can:
- define a function with
kaj - pass values into it
- return a result with
ferotDao - call the function when needed
If yes, you understand the basics of custom functions.