Skip to content
← Back to Community
How do i have a if statement with multible conditions
Profile icon

This is the first coding project ive ever done, and i cant figure out how to make a if statement with two conditions?

I think the project is attached ive never done this before

Profile icon
Profile icon

in order to use a if statment you need to use certain operators call Logical Operators.

The ones that you need are && and ||
&& is the and logical operator, and || is the or logical operator.

&& compares 2 conditions, works if both are true
|| compares 2 conditions, and works if at least 1 is true

var x = 1 var y = 5 /* The following if statment will run, because at least 1 condition is true */ if ((x === 1) || (y != 5)){ }

However, if we replace || with &&

/* The following if statment not run, because at only 1 condition is true. Both have to be true in order to run */ if ((x === 1) && (y != 5)){ }
Profile icon

Thanks that fixed it