Strings containing digits in JavaScript
Suppose we have a string containing only digits:
javascriptlet test = '12345'; // string with digits
Let's find, for example, the sum of its first and second characters:
javascriptlet test = '12345';
alert(test[0] + test[1]); // shows '12' - concatenates like strings
As you can see, the characters in our string
are also strings and are concatenated as strings.
Let's say we want to sum them as numbers.
We use the function Number for this aim:
javascriptlet test = '12345'; // string
alert(Number(test[0]) + Number(test[1])); // shows 3
Задание 1
Given the string '12345'.
Find the sum of the digits of this string.