Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Soccer League Coordinator in Swift

Kiran Radhakrishnan
seal-mask
.a{fill-rule:evenodd;}techdegree
Kiran Radhakrishnan
iOS Development Techdegree Student 3,809 Points

Need help with part 2

for (player, details) in playerInfo { if details[1] == "YES" && experiencedPlayerSharks <= 2 && sharks.count <= 6 {

    sharks[player] = details
    experiencedPlayerSharks += 1
} else if details[1] == "NO" && inexperiencedPlayerSharks <= 2 && sharks.count <= 6 {

    sharks[player] = details
    inexperiencedPlayerSharks += 1

} else if details[1] == "YES"  && experiencedPlayerDragons <= 2 && dragons.count <= 6 {

     dragons[player] = details
     experiencedPlayerDragons += 1

} else if details[1] == "NO" && inexperiencedPlayerDragons <= 2 && dragons.count <= 6 {

    dragons[player] = details
    experiencedPlayerDragons += 1

} else if details[1] == "YES"  && experiencedPlayerRaptors <= 2 && raptors.count <= 6 {

    raptors[player] = details
    experiencedPlayerRaptors += 1

} else if details[1] == "NO" && inexperiencedPlayerRaptors <= 2 && raptors.count <= 6 {

    raptors[player] = details
    inexperiencedPlayerRaptors += 1


} else {
    print("Al players have been assigned to different teams")
}

} print(sharks) print(dragons) print(raptors)

this is the result i get

Al players have been assigned to different teams Al players have been assigned to different teams

["Joe Smith": ["42", "YES", "Jim and Jan Smith"], "Suzane Greenberg": ["44", "YES", "Henrietta Dumas"], "Joe Kavalier": ["39", "NO", "Sam and Elaine Kavalier"], "Diego Soto": ["41", "YES", "Robin and Sarika Soto"], "Eva Gordon": ["45", "NO", "Wendy and Mike Gordon"], "Sal Dali": ["41", "NO", "Gala Dali"]]

["Bill Bon": ["43", "YES", "Sara and Jenny Bon"], "Ben Finkelstein": ["44", "NO", "Aaron and Jill Finkelstein"], "Arnold Willis": ["43", "NO", "Claire Willis"], "Matt Gill": ["40", "NO", "Charles and Sylvia Gill"], "Chloe Alaska": ["47", "NO", "David and Jamie Alaska"], "Kimmy Stein": ["41", "NO", "Bill and Hillary Stein"], "Sammy Adams": ["45", "NO", "Jeff Adams"]]

["Les Clay": ["42", "YES", "Wynonna Brown"], "Phillip Helm": ["44", "YES", "Thomas Helm and Eva Jones"], "Herschel Krustofski": ["45", "YES", "Hyman and Rachel Krustofski"]]

1 Answer

Kiran Radhakrishnan
seal-mask
.a{fill-rule:evenodd;}techdegree
Kiran Radhakrishnan
iOS Development Techdegree Student 3,809 Points

Nevermind. I figured it out :D

used a switch instead of all if else

for (player, details) in playerInfo { switch details[1] { case "YES" : if experiencedPlayerSharks <= 2 && sharks.count <= 6 { sharks[player] = details experiencedPlayerSharks += 1 } else if experiencedPlayerDragons <= 2 && dragons.count <= 6 { dragons[player] = details experiencedPlayerDragons += 1 } else if experiencedPlayerRaptors <= 2 && raptors.count <= 6 { raptors[player] = details experiencedPlayerRaptors += 1 } case "NO" : if inexperiencedPlayerSharks <= 2 && sharks.count <= 6 { sharks[player] = details inexperiencedPlayerSharks += 1 } else if inexperiencedPlayerDragons <= 2 && dragons.count <= 6 { dragons[player] = details inexperiencedPlayerDragons += 1 } else if inexperiencedPlayerRaptors <= 2 && raptors.count <= 6 { raptors[player] = details inexperiencedPlayerRaptors += 1 }

default: break
}