Ask Question
27 July, 09:31

jа vascript Write a function named sumNumbers that accepts a nonnegative number, adds up all of the numbers between 0 and the number (inclusive), and returns the sum.

+4
Answers (1)
  1. 27 July, 13:12
    0
    function sumNumbers (num) { let sum = 0; for (let i=0; i < = num; i++) { sum + = i; } return sum; }

    Explanation:

    Firstly, let's create a function named sumNumbers () that take one input parameter, num (Line 1).

    Declare a variable, sum, to hold the value of total number between 0 and the input number (Line 2). Initialize it with 0 value.

    Create a for-loop to traverse through the numbers started from 0 till input number (Line 3). In the loop, add the each number to sum variable (Line 4).

    At last, return the sum as output (Line 6).
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “jа vascript Write a function named sumNumbers that accepts a nonnegative number, adds up all of the numbers between 0 and the number ...” in 📙 Engineering if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers