user5632230
user5632230

Reputation:

Javascript - if and else code -

i am new to coding. I actually just started yesterday. And i have this problem with this code. I am using JavaScript. Here is the code:

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

Thank you.

Upvotes: -1

Views: 87

Answers (2)

Jeff
Jeff

Reputation: 25221

The correct format is

if(condition){
    //code to execute
}else{
    //code to execute
}

so you need:

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

Upvotes: 1

frontend_dev
frontend_dev

Reputation: 1719

Maybe you mean something like this:

var answer = "Jon";

if (answer.length * 2 / 3 === 2) {
  console.log("The answer makes sense!");
} else {
  console.log("Wrong Wrong Wrong");
}

At least this executes without errors, and I put your string in a variable or else your code would almost make no sense even if it works. Now you can assign any string to the value of "answer" and check the length.

Upvotes: 0

Related Questions