Solved

JavaScript If/else

Posted on 2013-11-21
3
340 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTPS jquery doesn't work 9 63
Where is java script information saved? 2 53
insert a falling animation of heart  in php 4 23
where is team.js? 3 26
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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 …
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…

809 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