Start learning free

LESSON 172 OF 677 · LOOPS & GLOBAL VARIABLES

Array Sum: Buggy Code in Kotlin

Practice

Inside the code editor we've tried to write a function that takes an array nums as argument and prints to the console the sum of all numbers in that array.

So when we called printSum(intArrayOf(1, 2, 3)), we expected our code to print:

6

because 1 + 2 + 3 = 6. But it seems like we made some mistakes because when we run our code, it prints:

1
2
3

Assignment:

Your task is to fix our function such that it correctly computes and prints the desired sum.

STEP 1 OF 1
    Ctrl + Enter to check