Solved

JavaScript If/else

Posted on 2013-11-21
3
343 Views
Last Modified: 2013-11-22
Hello expert,
Working on a Javascript tutoriaa at Codeacademy.

Input
If
("Jon".length * 2 / (2+1) === 2);
{
    console.log("The answer makes sense!")
} 
else 
{
console.log("Error error error");
}

Open in new window


The screen is saying there is a syntax
error at the line that has the 'else' keyword:
' Expected identifier and
instead saw 'else'. Missing semicolon.

But there is a semicolon after the console.log
statement. Any idea why it says it is looking for an identifier?

Thanks.

Allen in Dallas
0
Comment
Question by:9apit
  • 2
3 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 39666484
Line 1 : if MUST BE lowercase
Line 2 : REMOVE the semicolon : ;

if
("Jon".length * 2 / (2+1) === 2)
{
    console.log("The answer makes sense!")
} 
else 
{
console.log("Error error error");
}

Open in new window

0
 
LVL 9

Accepted Solution

by:
Sar1973 earned 250 total points
ID: 39668471
I'd also say:
if ("Jon".length * 2 / (2+1) == 2) {
    console.log("The answer makes sense!");
} else {
console.log("Error error error");
}

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 39668926
@Sar1973, You just add trouble with your comment
I don't see why you MUST reformat, change position of the bracket...
The following is valid:

if ("Jon".length * 2 / (2+1) == 2)
{



    console.log("The answer makes sense!");



}



else
{




console.log("Error error error");




}

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question