Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

for-loop  #308

Copy link
Copy link
@FatemehAmir

Description

@FatemehAmir
Issue body actions

why this simple code dosent work for this question?
Create a file named for-loop.js.

In that file define a variable named total and make it equal the number 0.

Define a second variable named limit and make it equal the number 10.

Create a for loop with a variable i starting at 0 and increasing by 1 each
time through the loop. The loop should run as long as i is less than
limit.

On each iteration of the loop, add the number i to the total variable. To
do this, you can use this statement:

 total += i  

When this statement is used in a for loop, it can also be known as an
accumulator. Think of it like a cash register's running total while each
item is scanned and added up. For this challenge, you have 10 items and
they just happen to be increasing in price by 1 each item (with the first
item free!).

After the for loop, use console.log() to print the total variable to the
terminal.

my answer:
var total = 0
var limit = 10
for (let i = 0; i < limit; i++) {
total += i
}
console.log(total)

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.