Challenge 2: Sum of Digits in a String
Given a string containing numbers, calculate the sum of those numbers.
We'll cover the following
Problem Statement
Implement a function that takes a variable testVariable
, which contains a string of digits, and prints the sum of those digits.
Input
A variable testVariable
containing a string of digits.
Output
Sum of the digits in the string
Sample Input
"345"
Sample Output
12
Try it Yourself
Try this challenge yourself before examining the solution. Good luck!
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.