Accessing the digits of a number in JavaScript

Let now we store not a number in quotes in a variable, but just a number. In this case, an attempt to access its individual character will return undefined, since such an access only works for strings:

javascriptlet test = 12345;
alert(test[0]); // shows undefined

let's convert our number to a string to solve the problem:

javascriptlet test = String(12345); // string
alert(test[0]); // shows '1' - everything works

Suppose now we want to find the sum of the first two digits:

javascriptlet test = String(12345); // string
alert(test[0] + test[1]); // shows '12' - concatenates like strings

Let's add the function Number so that the characters are summed as numbers:

javascriptlet test = String(12345); // string
alert(Number(test[0]) + Number(test[1])); // shows 3

I remind you that a problem of this kind will arise only with summation. When multiplying, for example, conversion to numbers can be omitted:

javascriptlet test = String(12345); // string
alert(test[1] * test[2]); // shows 6
Задание 1

The number given is 12345. Find the sum of the digits of this number.

Задание 2

The number given is 12345. Find the product of the digits of this number.

Задание 3

The number given is 12345. Rearrange the digits of this number in reverse order.