Snail In the Well JS unexpected identifier | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Snail In the Well JS unexpected identifier

Hi all! I'm not looking for a direct solution to the whole problem, just a syntax error in having. Here is my code: function main() { var depth = parseInt(readLine(), 10); //your code goes here var day = 7; var night = -2; var dist = 0; for (i = 0; i <= depth; i++) { if dist >= depth { console.log(i); } else dist += day; if dist >= depth { console.log(i); } else dist += night; } }; My question is: I'm getting a syntax error on line 8 saying that "dist" is an unexpected identifier. However, I declared var dist in line 6. Can anyone help me understand why this is problematic? Thanks!

30th Jan 2023, 6:25 PM
Michaela Rehm
Michaela Rehm - avatar
0 Answers