HTML Academy
Simple comparisons
Conditions4/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?”
Equality, inequality
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Comparisons permitting equality

Excellent, the market analyzer of the Muffin by the colors of markers in the sales department works fine.

But we got a little problem: the flipchart also has some blue markers that managers use to highlight risky transactions. The Muffin completed its analyzer taking these markers into account, but the program has some errors once again: we get messages that the forecast is unacceptable.

To fix the new version of the analyzer, we need to study two more operators used for comparison. If it is known that one number may be greater than or equal to another, the “greater than or equal to” operator >= is used. Similarly, if the first number can be less or equal, the “less than or equal to” <= operator is used.

The program is supplemented by two more conditions and they need to be corrected again.

Comments

  • script.js
JavaScript
var red = 1; var yellow = 2; var green = 3; var blue = 2; if (blue > yellow) { console.log('There are just as many blue markers as there are yellow ones or even more. The risks are great.'); } else { console.log('Wrong! The forecast is unacceptable!'); } if (blue < yellow) { console.log('There are just as many blue markers as there are yellow ones or less. Risks are optimal.'); } else { console.log('Wrong! The forecast is unacceptable!'); } if (red < yellow) { console.log('Red markers are in the minority. The forecast is moderately positive!'); } else { console.log('Wrong! The forecast is unacceptable!'); } if (green > yellow) { console.log('Green markers prevail over the yellow ones. The forecast is positive!'); } else { console.log('Wrong! The forecast is unacceptable!'); }

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

Correct the code of the modified program to compare the number of markers.

  1. Replace the comparison operator with >= in the first if.
  2. Replace the comparison operator with <= in the second if.

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.