Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JavaScript If/else

Posted on 2013-11-21
3
Medium Priority
?
350 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:Allen Pitts
  • 2
3 Comments
 
LVL 83

Assisted Solution

by:leakim971
leakim971 earned 1000 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 1000 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 83

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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

916 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