The Number Adder

Easy+15 XP

Mission Briefing

The Grand Treasury needs to calculate the total gold accumulated over n days. Adding them up manually is out of the question!

The Concept: For Loops

A for loop is perfect for running a block of code a specific number of times. It has three parts:

  1. Initialize: let i = 1 (Start counting at 1)
  2. Condition: i <= 5 (Keep looping as long as i is 5 or less)
  3. Increment: i++ (Increase i by 1 after each loop)

The Objective

Your function receives a number n.

  1. Use a for loop to calculate the sum of all numbers from 1 to n inclusive.
  2. Return the final sum.

01EXAMPLE 1

Inputn = 3
Output6

Explanation: 1 + 2 + 3 = 6

Constraints

  • Use a for loop.
FundamentalsLoops
JavaScript
Loading...
3 Hidden

Input Arguments

n3

Expected Output

6

Click RUN to test your solution