Solved

JavaScript If/else

Posted on 2013-11-21
3
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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 …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

615 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