Bird
0
0

You want to create a Swift function that counts how many vowels are in a given String. Which approach correctly uses Character and String types?

hard📝 Application Q15 of 15
Swift - Data Types
You want to create a Swift function that counts how many vowels are in a given String. Which approach correctly uses Character and String types?
AIterate over the String's characters and check if each Character is a vowel
BConvert the String to Int and count vowels
CUse Character type to store the whole String and count vowels
DUse Bool type to store vowels and count them
Step-by-Step Solution
Solution:
  1. Step 1: Understand the problem

    We need to check each letter in a String to see if it is a vowel.
  2. Step 2: Choose correct types and method

    Iterating over a String gives Characters one by one, which can be checked against vowels.
  3. Step 3: Analyze options

    Iterate over the String's characters and check if each Character is a vowel correctly describes iterating over Characters in a String. Options A, B, and D misuse types or concepts.
  4. Final Answer:

    Iterate over the String's characters and check if each Character is a vowel -> Option A
  5. Quick Check:

    Check each Character in String for vowels [OK]
Quick Trick: Loop over String characters to check each letter [OK]
Common Mistakes:
  • Trying to convert String to Int for counting
  • Using Character to hold whole String
  • Using Bool incorrectly to count vowels

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes