HTML Academy
Logical negation
Conditions15/17
Back to the list of tasks
  • 1. Simple fork
  • 2. Let’s use an alternative
  • 3. Simple comparisons
  • 4. Comparisons permitting equality
  • 5. Equality, inequality
  • 6. Strict string comparison
  • 7. Strict number comparison
  • 8. Condition-based actions
  • 9. If the condition is not fulfilled
  • 10. Values ​​as a condition
  • 11. Nested conditions
  • 12. Logical operators: &&, ||
  • 13. Logic traps
  • 14. Logical negation
  • 15. Let’s combine logical operators
  • 16. Summary of “Conditions”
  • 17. Second program: “How long to take a walk for?”
Summary of “Conditions”
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Let’s combine logical operators

Now that you have learned how to use negations, we can describe a new logic of the program that will work without errors.

We need to combine two separate checks into one single check. The project can be started if:

  • there are enough developers
  • and they have the knowledge of the technologies
  • and no developers are on vacation
  • and no developers are out sick.

Implementing this logic in the code is quite easy, because negations can be combined with other logical operators. Example:

var conditionOne = true;
var conditionTwo = true;
var conditionThree = false;

if (conditionOne && conditionTwo && !conditionThree) {
  // code will be executed
}

It’s time to complete the third program of this work day!

Comments

  • script.js
JavaScript
var enoughDevelopers = false; var techAvailable = false; var onVacation = false; var onSickLeave = false; if (enoughDevelopers && techAvailable) { console.log('You can start the project'); }

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

Console

The code has changed, click “Run” or turn autorun on.

Result

Goalscompleted

Let’s complete the program and check its behavior.

  1. Add !onVacation condition at the end of the check using “logical AND”.
  2. And after it, also using “logical AND” !onSickLeave condition.
  3. Now add the else fork and log the 'You cannot start the project' message in it.
  4. Correct the values ​​of the variables so that the condition is fulfilled.
  5. Then indicate that someone from the developers is on vacation and make sure that the project cannot be started.

Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

VISAMastercard

Log in

or

Forgot your password?

Sign up

Sign up

or
Log in

Restore access

Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

Forgot to connect your email to the profile? Email us and we’ll help.