UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Need help with a free coding question on Unwrap

Forums > Swift

Hi,

I'm stuck on the 'Free Coding' question in Unwrap that asks you to write a function that accepts two strings and returns as true if they are both the same regardless of what letter case they are written in.

The code I have included below works fine in Xcode, but isn't accepted by the app. Can anyone give me an alternative answer?

func twoStrings (A: String, B: String) -> Bool { if A.uppercased() == B.uppercased() { return true } else if A.lowercased() == B.lowercased() { return true } else { return false } }

Thanks

2      

You made it too complicated I think

func twoString(A: String, B: String) -> Bool {
  if A.uppercased() == B.uppercased() {
      return true
  }

  return false
}

You just need to make sure both are the same case then if the are the same then it is true everything else is false.

3      

Thanks very much.

I see now all I had to do was make sure both strings were the same in one case rather than both.

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.