Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKiran Radhakrishnan
iOS Development Techdegree Student 3,809 PointsNeed 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
iOS Development Techdegree Student 3,809 PointsNevermind. 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
}