Ask Question
12 October, 19:05

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.

+3
Answers (1)
  1. 12 October, 20:24
    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?
Find 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 you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers