Jump to content

If Statements in Java

Recommended Posts

Hey guys!

I'm struggling to get the correct code on this following example:

var weather = "sunny" ;

var IamHappy = true;


I'm trying to create a code with the if statement that will evaluate the condition  if the weather is sunny and I'm feeling happy. If so, it should print on the code block " Lets run".

what I have tried is this

if ( weather  & IamHappy == "sunny" ) {

    console.log("Lets run"); 


I'm still learning the basics of coding, but any help would much appreciated.






Link to post
Share on other sites

Two problems I notice:

  1. The operator should be "&&"
  2. The value you want to compare with "sunny" is weather, not IamHappy.

To fix it, the line should look like this:

if(IamHappy && weather == "sunny") {

By the way, this is Javascript, not Java. They're two different languages.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...