If else statement on javascript


#1

if(3*2/(2+1) === 2) {
console.log("The answer is true");
} else {
console.log("Error Error Error");
}

get this messge back ----- thanks if anyone can help me out. i tried everything. its does evaluate to true but still wont go next lesson

Oops, try again.
Make sure your if/else statement evaluates to true!

#2

Can you specify your task.

Im preety sure your suppose to return true... So change your console.logs to return true;(for if statement) and return false;(for else statement)


#3

@amanuel2 This would be a possibility if there was a function involved. From the code posted by the OP there is no function.

@systemrockstar63118 It would help to know which exercise you are working on.


#4

i have the same problem

Getting Started with Programming











        Computers are smart


        Great! We used an if statement to do something if the answer to the condition was yes, or true as we say in JavaScript.

In addition to doing something when the condition is true, we can do something else if the condition is false. For example, if your name is shorter than 7 letters, we can respond with "You have a short name!" We can do this using an if / else statement:

if( "myName".length >= 7 ) {
console.log("You have a long name!");
}
else {
console.log("You have a short name!");
}

Just like before, if the condition is true, then only the code inside the first pair of curly braces will run. Otherwise, the condition is false, so only the code inside the second pair of curly braces after the else keyword will run.

In the example above the condition "myName".length >= 7 evaluates to false since "myName" only has 6 letters. Since the condition is false, only the code inside the curly braces after the else keyword runs, and prints out You have a short name!.

      
    
    
      
        Instructions
      
      
        In line 1, fill in a condition that will evaluate to falseFill in some code to run in the else portion (this will run if the condition is false). Use console.log for this part.

          
            
              
                ?
                
                  
                  Hint
                
              
              

                You can write a condition with an inequality like 10 < 5:

if (10 < 5) {
// This won't run, since 10 > 5
}
else {
// This part WILL run!
}