javascripting icon indicating copy to clipboard operation
javascripting copied to clipboard

for-loop

Open FatemehAmir opened this issue 4 years ago • 5 comments

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)

FatemehAmir avatar Dec 25 '20 10:12 FatemehAmir

@FatemehAmir what is the error you are seeing?

itzsaga avatar Dec 27 '20 19:12 itzsaga

Can I have a screen shot

On Tue, Mar 9, 2021 at 4:29 PM Alexandria @.***> wrote:

I am having the same problem, for this lesson my code is

let total = 0; limit = 10; for (let i = 0; i+=1; i < limit) { total =+ i }

And when I run javascripting verify for-loop.js, my terminal is on stuck loading

JAVASCRIPTING

FOR LOOP (Exercise 10 of 20)

I waited a good 10 minutes, and it has not progressed. All the other exercises worked fine for me until the for-loops

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/workshopper/javascripting/issues/308#issuecomment-794542415, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARMAIHTQ3WJEDRXEMLSRNNLTC2HNPANCNFSM4VJAQ55A .

wiiffiiwee avatar Mar 09 '21 22:03 wiiffiiwee

I think they are running into the same problem as me

image

alxndriab avatar Mar 09 '21 22:03 alxndriab

@alt-ab you have little typo on line 4. I think total += i will be okay.

marocchino avatar Mar 10 '21 03:03 marocchino

Alright thank you! It worked well!

alxndriab avatar Mar 22 '21 03:03 alxndriab