Skip to content
LearnStack
JavaScript curriculum

JavaScript practice

Short exercises. Try them first, open the hint if you are stuck, and the solution last.

  1. Exercise 1

    Even or odd

    Write isEven(n) that returns true when n is even. Then print isEven(4) and isEven(7).

    Your solutionJavaScript
  2. Exercise 2

    Sum to n

    Write sumTo(n) that adds 1 + 2 + ... + n using a loop. sumTo(5) should be 15.

    Your solutionJavaScript
  3. Exercise 3

    FizzBuzz

    Print numbers 1 to 15. For multiples of 3 print Fizz, multiples of 5 print Buzz, multiples of both print FizzBuzz.

    Your solutionJavaScript