Author Topic: Javascript help  (Read 2096 times)

So I just started out on this codeacademy website learning Javascript.  I got to the if/else statements and my first one ran fine but my second one, even though it was entirely identical to the first one apart from the string that was being console logged, would not run.

Here it is:
Code: [Select]
if (54>67);
{
    console.log("I am right");
}
else;
{
    console.log("I am wrong");
}
It keeps giving me a red x next to the "else" saying "Expected an identifier and instead saw 'else'"

Please help me if you can.

ok I don't know any javascript but are you sure the semicolons are supposed to come after the if statements?

by putting a semicolon, you ended the else statement. remove the semicolon after the else. in fact there shouldn't be one after the if iirc.

I'm learning Java from codecademy too.

try removing the semicolons in front of "if" and "else"

I'm learning Java from codecademy too.

codecademy doesn't teach java tho.

I'm learning Java from codecademy too.
java =/= javascript. i made this mistake too lol

java =/= javascript. i made this mistake too lol

Ah good to know.  I'm just used to Java programs and stuff that I just call it "Java".

Code: [Select]
if (54>67)
{
    console.log("I am right");
}
else
{
    console.log("I am wrong");
}

As everyone was saying, you don't put semicolons there. I think they could explain why better, though. Above is the fixed version.

If statements aren't a function, and don't require a semicolon.
Code: [Select]
if(54>67) {
    console.log("I am right");
}
else {
    console.log("I am wrong");
}

A safe rule of thumb is semicolons only go after function calls and variable declarations. There are probably some special cases where they're used, but I don't know JS very well.

python would really be better. You can get the hang of it quick.

python would really be better. You can get the hang of it quick.

Except for the whole not teaching you Javascript thing.


I'm learning Java from codecademy too.

I had two semesters of Java, we started getting into GUI stuff. It turns out the Comp Sci department never ever uses Java again. It's all C++ and C for every other class.

python would really be better. You can get the hang of it quick.
Because Python is certainly HTML compatible and runs natively in your browser, on both desktop and mobile.

:/

Except for the whole not teaching you Javascript thing.


I had two semesters of Java, we started getting into GUI stuff. It turns out the Comp Sci department never ever uses Java again. It's all C++ and C for every other class.
C/C++'s syntax is similar enough. You're not really at much of a loss.