HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <p>Work on the program is in full swing and the Muffin asks us to make several changes to the logic of decision-making:</p>
1 <p>Work on the program is in full swing and the Muffin asks us to make several changes to the logic of decision-making:</p>
2 <ul><li>The project can be started if there are enough developers<em>and</em>if they have the knowledge of the necessary technology.</li>
2 <ul><li>The project can be started if there are enough developers<em>and</em>if they have the knowledge of the necessary technology.</li>
3 <li>The project cannot be started if one of the developers is on vacation<em>or</em>is on sick leave.</li>
3 <li>The project cannot be started if one of the developers is on vacation<em>or</em>is on sick leave.</li>
4 </ul><p>We already know how to implement the first part of the logic, the one that contains and, using nested conditions. But what about the second part: the one that includes or? We can combine conditions inside if using logical operators: &amp;&amp; and ||. For example:</p>
4 </ul><p>We already know how to implement the first part of the logic, the one that contains and, using nested conditions. But what about the second part: the one that includes or? We can combine conditions inside if using logical operators: &amp;&amp; and ||. For example:</p>
5 var conditionOne = true; var conditionTwo = true; var conditionThree = false; var conditionFour = true; if (conditionOne &amp;&amp; conditionTwo) { // code will be executed } if (conditionThree || conditionFour) { // code will also be executed }<p>The &amp;&amp; operator or “logical AND” returns true only if <em>both</em>conditions, to the left and right of it, return true.</p>
5 var conditionOne = true; var conditionTwo = true; var conditionThree = false; var conditionFour = true; if (conditionOne &amp;&amp; conditionTwo) { // code will be executed } if (conditionThree || conditionFour) { // code will also be executed }<p>The &amp;&amp; operator or “logical AND” returns true only if <em>both</em>conditions, to the left and right of it, return true.</p>
6 <p>The operator || or “logical OR” returns true if <em>any</em>from the conditions to the left or to the right of it return true.</p>
6 <p>The operator || or “logical OR” returns true if <em>any</em>from the conditions to the left or to the right of it return true.</p>
7 <p>Now it is clear how to program the second part of the logic: let’s combine the conditions “employees on vacation” and “employees on sick leave” using “logical OR”.</p>
7 <p>Now it is clear how to program the second part of the logic: let’s combine the conditions “employees on vacation” and “employees on sick leave” using “logical OR”.</p>
8 <p>We can also program the first part of the logic without nested if: let’s combine the conditions “there are enough developers” and “technology is mastered” using the “logical AND”. We decided not to nest the conditions as this could make the code complicated and confusing. If the nesting is large, then it becomes difficult to understand why this or that action is being performed.</p>
8 <p>We can also program the first part of the logic without nested if: let’s combine the conditions “there are enough developers” and “technology is mastered” using the “logical AND”. We decided not to nest the conditions as this could make the code complicated and confusing. If the nesting is large, then it becomes difficult to understand why this or that action is being performed.</p>