Ask Question
7 April, 04:58

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. 7 April, 05:01
    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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers