Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function that returns the sum of all digits in a given integer.

Medium

Problem Statement

Write a function that returns the sum of all digits in a given integer.

Sample Input

num = 1234

Sample Output

10

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Calculate the sum of all digits in an integer function sumOfDigits(num) { } console.log(sumOfDigits(1234));
Log in or sign up to run or submit your code.Log inSign up
Input
num = 1234
Expected Output
10