WWDC24 SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: Day 4: Checkpoint 2

Forums > 100 Days of SwiftUI

Hey everyone, first time posting on the forum. I wanted to check and see if I had gotten the scope of the checkpoint

Description: This time the challenge is to create an array of strings, then write some code that prints the number of items in the array and also the number of unique items in the array.

My Solution:

var teams = ["Mavs", "Cavs", "Nuggets", "Wolves", "Pacers", "Celtics", "Knicks", "Thunder"] print(teams.count)

teams.append("Cavs") teams.append("Mavs") print(teams.count)

let uniqueTeams = Set(teams) print(uniqueTeams.count)

   

As it your first post. You need to put code inside backtick eg var teams = ["Mavs", "Cavs", "Nuggets", "Wolves", "Pacers", "Celtics", "Knicks", "Thunder"] or use three backtick or </> in above for code block so your code looks like this

var teams = ["Mavs", "Cavs", "Nuggets", "Wolves", "Pacers", "Celtics", "Knicks", "Thunder"] 

print(teams.count)

teams.append("Cavs")
teams.append("Mavs") 
print(teams.count)

let uniqueTeams = Set(teams) 
print(uniqueTeams.count)

Yes you have it correct, the only thing is that that console prints

8
10
8

which is not very helpful but with a print() you can have multi arguments eg

print("Teams Count:", teams.count)

if you did it then the output could look like this

Teams Count: 8
New Teams Count: 10
Unique Teams Count: 8

KEEP CODING

1      

Also:

See -> How to Post Code

or See -> How to Post Code #2

or this message -> How to Post Code #3

Keep Coding™

1      

Thank you!

   

Save 50% in my WWDC sale.

SAVE 50% To celebrate WWDC24, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.