S
S
shemshen2021-07-13 16:49:26
JavaScript
shemshen, 2021-07-13 16:49:26

Running a Javascript for loop?

Why is +2 not added after the first alert?

let age=+prompt("Введите возраст до 16 лет");
for (q=0; q<age; q++){
let name="Кушо  ";
alert (name+(age+2));
age-=3;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2021-07-13
@firedragon

Because browsers don't like spammers.
Can you imagine a thousand windows popping up?

V
Vasily Bannikov, 2021-07-13
@vabka

Xs what should be added here, but here is the result:

age=1
Кушо 3
-2

age=2
Кушо 4
-1

age=3
Кушо 5
0

age=4
Кушо 6
1

age=5
Кушо 7
Кушо 4
-1

age=6
Кушо 8
Кушо 5
0

age=7
Кушо 9
Кушо 6
1

age=8
Кушо 10
Кушо 7
2

age=9
Кушо 11
Кушо 8
Кушо 5
0

age=10
Кушо 12
Кушо 9
Кушо 6
1

age=11
Кушо 13
Кушо 10
Кушо 7
2

age=12
Кушо 14
Кушо 11
Кушо 8
3

age=13
Кушо 15
Кушо 12
Кушо 9
Кушо 6
1

age=14
Кушо 16
Кушо 13
Кушо 10
Кушо 7
2

age=15
Кушо 17
Кушо 14
Кушо 11
Кушо 8
3

age=16
Кушо 18
Кушо 15
Кушо 12
Кушо 9
4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question