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:
- Initialize:
let i = 1(Start counting at 1) - Condition:
i <= 5(Keep looping as long asiis 5 or less) - Increment:
i++(Increaseiby 1 after each loop)
The Objective
Your function receives a number n.
- Use a
forloop to calculate the sum of all numbers from 1 to n inclusive. - Return the final sum.
01EXAMPLE 1
Input
n = 3Output
6Explanation: 1 + 2 + 3 = 6
Constraints
- Use a for loop.
FundamentalsLoops
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
n3
Expected Output
6
Click RUN to test your solution