Start learning free

LESSON 84 OF 349 · CONDITIONAL STATEMENTS - CHALLENGES

Leap Year in Swift

Practice

A leap year happens every four years, so it's a year that is perfectly divisible by four.

However, if the year is a multiple of 100 (1800, 1900, etc), the year must be divisible by 400 to be leap.

Write a function that determines if the year is a leap year or not.

Examples:

leapYear(2020) ➞ true

leapYear(2021) ➞ false

leapYear(1968) ➞ true

leapYear(1900) ➞ false

Video Solution:

STEP 1 OF 4
    Ctrl + Enter to check

    Leap Year in Swift

    Keep going with SwiftAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free