Digits in a message
Inputs
text is 0 to 20 characters: lowercase letters and the digits 0 to 9.
Your tasks
- Create a number
totalthat starts at 0. - Use a loop over
text. When a character is a digit, convert it to a number and add it tototal. - Complete
digitTotalso it returnstotal. Return it, do not print it.
Example
With text = "a1b2c9", digitTotal returns 12.
Rules
- Ignore letters.
Test data
TEST DATA 1: text is "a1b2c9"
TEST DATA 2: text is "abc"
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.