Syntax in course can be confusing and all over the place


#1

Not stuck anywhere but the syntax of the examples changes throughout the course (first really noticed it with if/else statements.)
Some look like:

if (blah) {
blahblahblah;
}
else
{
blahblah;
}

while others look like:

if (blah) {
blahblahblah;
} else {
blahblah;
}

Both work fine but when people don't know which to do they will forget which is "correct" and use both, and their code will look terrible.

Then, when it is explaining how to write a function, it says to be sure to put a semicolon after every line in the body and one after the ending curly brace; but the in-line debugger will say, when you put the semicolon after the ending curly brace, that it is unnecessary - which i believe it is.

Confusing people should be the exact opposite of what this course is supposed to do, so I think syntax guidelines should be implemented and the course updated..

This is throughout the course and not just one specific part so I put it in "Getting Started."


#2

There is no one correct way to write code blocks. It is a style preference of the author or collaborative group. For my own purposes, I prefer your second example.

if (...) {    // opening curly brace on same line as keyword

}             // closing curly brace on its own line

For nested blocks, it is common to use indentation to indicate the nesting level. JavaScript ignores white space so it has no effect on how the code executes, but it sure goes a long way to making the code easy to read and debug.

var func = function (a, b) {
    for (var i = a; i < b; i++) {
        if (i * a < b) {
            console.log(i * a);
        } else {
            console.log(b / i);
        }
    }
};

Of course the above code is meaningless, but it serves as an example of nesting, and placement of braces.


#3

Ooops yes i forgot to indent there. I was focusing on the difference in brace placement. I just think that the examples in the course should be uniform in order to keep from making the learner question themselves.

(That's my preferred method too. :slight_smile:)


#4

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