Review question


I am receiving the error "Unexpected end of input" and cannot find what or where the error is.

for (var i = 1; i<60; i-=2.2);{

var xx = true
    console.log("I'm a winner!");
    xx = false;}

var condition = false
do {
    console.log("I'm an even bigger winner");


Make some observations on your own, what you you expect your code to do and what is it instead doing?

Ask yourself why it wouldn't behave like it does, or why it would do what you expect. Which part of the code is responsible for that? That's probably where the problem is


I expect the for values to print and then the while and do values to print. It's not shutting down so I don't have an infinite loop anywhere, just a syntax error.


If I run what you posted locally, there's this error message:

$ node hello.js
SyntaxError: Unexpected token }

That doesn't even exist in your code, it got modified a bit by the interpreter before it ran it. But the line number is right.

Having read what it (the interpreter) has read so far, end-of-file is not something that's allowed to come at that point. Something else has to come first. That's what your interpreter is saying with end of input. The one I'm running it gets a different issue because it changed the code prior to running it, but the problem is still the same with your original code. You'll need to compare what you did there with some reference for the thing you are doing - you haven't quite got the syntax right for that loop, so how is the syntax for that supposed to look like?


The exercise calls for three separate for/while/do loops. This is what they give as examples.

for (var i = 1; i < 11; i++) {

var condition = true;
while(condition) {
// Avoid infinite loops!
condition = false;
var condition = false;
do {
console.log("I'm printed once!");
} while(condition);


And the last one in your code, where the syntax error is reported, doesn't match what you posted just now. It's just a matter of comparing, they're 3-4 lines.

Also, a (somewhat crude) method of narrowing things down is to remove parts of the code until there's only just enough to produce the error. That stripped down piece of code would be easier to compare to a reference.
(One would want to do this in a separate file or at least make a backup, or comment it out while testing)


I figured it out. I just had to move something up a line. Stupid simple solution took me ■■■■ near an hour.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.