Code Challenges
Solve problems, earn XP, and level up your skills.
Hello World Function
Write a function called `greet` that takes a name as a parameter and returns the string "Hello, [name]!". Example: greet('Alice') → "Hello, Alice!" greet('World') → "Hello, World!"
Sum of Two Numbers
Write a function `add(a, b)` that returns the sum of two numbers. Example: add(2, 3) → 5 add(-1, 1) → 0 add(0, 0) → 0
Even or Odd
Write a function `isEven(n)` that returns `true` if the number is even, or `false` if it is odd. Example: isEven(4) → true isEven(7) → false isEven(0) → true
Reverse a String
Write a function `reverseString(str)` that returns the string reversed. Example: reverseString('hello') → 'olleh' reverseString('world') → 'dlrow' reverseString('abcd') → 'dcba'
Factorial
Write a function `factorial(n)` that returns the factorial of a non-negative integer. Factorial is the product of all positive integers up to n. Example: factorial(5) → 120 (5 × 4 × 3 × 2 × 1) factorial(0) → 1 factorial(3) → 6
Find Maximum in Array
Write a function `findMax(arr)` that returns the largest number in an array. Example: findMax([1, 3, 2]) → 3 findMax([10, 5, 20]) → 20 findMax([-1, -5, -3]) → -1
Count Vowels
Write a function `countVowels(str)` that returns the number of vowels (a, e, i, o, u) in a string (case-insensitive). Example: countVowels('hello') → 2 countVowels('JavaScript') → 3 countVowels('rhythm') → 0