Skip to content
How do i have a if statement with multible conditions
Profile icon
DanielRidlon

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

You are viewing a single comment. View All
Profile icon
emilyDoesPascal

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
DanielRidlon

Thanks that fixed it


@coreDumpedSeg