30+ Practice Exercises
Tiny problems sorted by difficulty. Open the playground in another tab and work through them at your own pace.
Easy (1-2 Concepts Each)
- FizzBuzz lite — print numbers 1 to 20.
- Sum two numbers — write a function
add(a, b). - Greet someone — write
greet(name)that returns "Hello, NAME!". - Even or odd — return "even" or "odd" given a number.
- Larger of two — return whichever of two numbers is bigger.
- Count vowels — count vowels in a string.
- Reverse a string — return the string backward.
- Length of string — without using built-in
length. - Is the year a leap year? — divisible by 4, but not by 100 unless also by 400.
- Convert °C to °F — formula: F = C * 9/5 + 32.
Medium (3-4 Concepts)
- FizzBuzz classic — print 1 to 100, "Fizz" for multiples of 3, "Buzz" for 5, "FizzBuzz" for both.
- Sum of an array — without built-in
reduce. - Average of an array — sum / length.
- Find the largest — maximum value in an array.
- Count words — count words in a sentence.
- Capitalize first letter of every word.
- Remove duplicates from an array.
- Filter evens — return only even numbers from a list.
- Tip calculator — given bill and percent, return tip and total.
- Palindrome check — is the string the same forward and backward?
Harder (Uses 5+ Concepts)
- To-do list — array of objects with
{ task, done }; functions to add, complete, list. - Number guessing game — random target, user guesses, "higher/lower" feedback.
- Roman numerals — convert a number to Roman numerals up to 100.
- Caesar cipher — shift each letter by N.
- Word frequency counter — given a paragraph, return most common words.
- Bank balance — start at 0; functions
deposit,withdraw(no overdrafts). - Tic-tac-toe board — represent a board, check for winners.
- Pig Latin translator — move first letter to end + "ay".
- Validate email — does the string have @ and a dot after?
- Simple calculator — function that takes two numbers and an operator, returns the result.
- Fibonacci sequence — print the first N Fibonacci numbers.
- Anagram check — are two strings anagrams of each other?
💡
Approach
Solve each one in your head first. Then write a rough version. Then clean it up. Don't Google a solution until you've been stuck for at least 20 minutes — the stuck time is where learning happens.