⊗jsrtPmFcInr 31 of 112 menu

Using Functions in React

You can make auxiliary functions inside the main function of the component. For example, let's use auxiliary functions to find the sum of the powers of two numbers and display it in the tag text:

function App() { function square(num) { return num ** 2; } function cube(num) { return num ** 3; } const sum = square(3) + cube(4); return <div> {sum} </div> }

Create a function getDigitsSum that will find the sum of the digits of the number passed. Use it to display the sum of the digits of the number 123.

enru