0

Repeat and Learn Code! Code! Code!

https://sololearn.com/coach/1239/?ref=app var expression = readLine(); for (let i = 0;i<3;i++) { console .log(expression ); }

14th Sep 2021, 11:04 AM
Khomi TAKAYANAGI
Khomi TAKAYANAGI - avatar
5 Answers
+ 2
Khomi TAKAYANAGI let is block scope means if you try to access i outside the loop it will give error but if you use var instead of let then you can access i outside the loop. var expression = readLine(); for (let i = 0;i<3;i++) { console .log(expression ); } console.log(i);//error: i is not defined ------------- var expression = readLine(); for (var i = 0;i<3;i++) { console .log(expression ); } console.log(i); //no error and print 3
14th Sep 2021, 11:14 AM
A͢J
A͢J - avatar
+ 4
Khomi TAKAYANAGI , your code should work fine, so what is your question?
14th Sep 2021, 11:09 AM
Lothar
Lothar - avatar
+ 1
Khomi TAKAYANAGI Working fine what is issue here?
14th Sep 2021, 11:08 AM
A͢J
A͢J - avatar
+ 1
I don't understand enough how to use "let"
14th Sep 2021, 11:10 AM
Khomi TAKAYANAGI
Khomi TAKAYANAGI - avatar
+ 1
var expression = readLine() for (var i = 0 ; i < 3 ; i ++){console.log(expression);} it worked. var expression = readLine() for (var i = 0 ; i < 3 ; i ++){console.log(i);} //no error but it outputs 0 1 2 ÂżHow can I decide to use "var" or "let"?
14th Sep 2021, 11:26 AM
Khomi TAKAYANAGI
Khomi TAKAYANAGI - avatar