Count capitals
Inputs
text is 0 to 24 characters: letters (a to z, A to Z) and spaces.
Your tasks
- Create a number
countthat starts at 0. - Use a loop over
text. Add 1 tocountwhen a character is a capital letter (A to Z). - Complete
countCapitalsso it returnscount. Return it, do not print it.
Example
With text = "Hello World", countCapitals returns 2.
Rules
- Spaces and lowercase letters do not count.
Test data
TEST DATA 1: text is "Hello World"
TEST DATA 2: text is ""
Practice focus
Text is just a list of characters, so everything you know about lists applies. String problems in interviews are array problems with letters.