DEV Community

Cover image for Simple Swift Challenges
Shanice
Shanice

Posted on

Simple Swift Challenges

Greetings 👋,

I've constructed 5 basic Swift challenges and listed them below. First, you'll find the challenges and further down the page you'll find the solutions. If you aren't able to solve them, before looking at the solutions, try to find some help through a Google search or at https://developer.apple.com/documentation/swift

Have fun :)

  1. Create a variable named greeting, assign it to the String hello, and print it to the console

  2. Create a constant named pi and assign it to the Double 3.14, and print it to the console

  3. Create a multiline string with the sentence - I love to eat, eat, eat, apples and bananas

  4. Count the amount of characters in the multiline string

  5. Print the multiline string in uppercase letters

*
*
*
*
*
*
*
*
*
*

  1. Create a variable named greeting, assign it to the String hello, and print it to the console

var greeting = "hello"
print(greeting)

  1. Create a constant named pi and assign it to the Double 3.14, and print it to the console

    let pi = 3.14
    print(pi)

  2. Create a multiline string with the sentence - I love to eat, eat, eat, apples and bananas

    var eatWhat = """
    I love to
    eat, eat, eat,
    apples and bananas.
    """

  3. Count the amount of characters in the multiline string

    print(eatWhat.count)

  4. Print the multiline string in uppercase letters

    print(eatWhat.uppercased())

Top comments (0)