Create functions: 15 levels of parameters, return, arrow vs declaration and default values. A JavaScript functions game for mastering reusable code.
A function is a block of code that can be called repeatedly. A function can take parameters (input) and return a value with return.
The if...else statement lets code branch based on a condition. The % (modulo) operator returns the remainder of a division.
Strings have many built-in methods. .repeat(n) repeats a string n times. You can also use a loop to build the string manually.
To process each element of an array, you can use a for loop or a method like .reduce(). A for loop iterates one by one, .reduce() accumulates a value.
A default parameter lets a function have a fallback value if the parameter isn't given. It's written with = after the parameter name.
The .filter() method makes a new array of the elements that pass a condition. Its callback must return true (keep) or false (drop).
sapa that takes a nama parameter and returns the string "Halo, {nama}!".luasPersegi that takes a sisi parameter and returns the area of a square (sisi x sisi).genapGanjil that takes a number and returns "genap" or "ganjil".maks that takes two numbers and returns the bigger one.ulang that takes a string kata and a number n, then returns that word repeated n times (without spaces).jumlah that takes an array of numbers and returns their total sum.sapaPagi that takes nama (default: "Teman") and returns "Selamat pagi, {nama}!".fizzBuzz that takes a number. Return "Fizz" if it's divisible by 3, "Buzz" if divisible by 5, "FizzBuzz" if divisible by both, or the number itself (as a string).positifSaja that takes an array of numbers and returns a new array containing only the positive numbers (> 0).buatProfil that takes nama and umur, then returns the object { nama, umur, dewasa } where dewasa is true if umur >= 17.hitungKata that takes a sentence string and returns the number of words in it. Words are separated by spaces.pangkat (power) that takes base and exp (an integer >= 0) and returns base raised to the power exp. Use recursion (no ` or Math.pow`).And more, 20 levels in all.