HTML Academy
Let’s use an alternative
Conditions3/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?”
Comparisons permitting equality
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Simple comparisons

In the previous task, we compared the daily amount of eaten food with the daily amount of food that the Muffin can eat. And we solved one more task of the boss.

But it’s getting even more difficult after this. Therefore, while we have a little break before the next task, let’s see how to use the comparison correctly.

In this task, we will practice using the operators “more” > and “less” <, dealing with correcting errors in the experimental development projects of the boss.

The Muffin found several markers of different colors on the flipchart of the sales department: one red, two yellow and three green. The boss decided that the colors of the markers are an excellent basis for predicting the market. He even wrote an analytical program, which should compare the number of markers and derive the corresponding forecasts. But the comparisons do not work for some reason: messages are logged saying that the forecast is unacceptable, although forecasts should be positive.

We must understand what is happening and correct the program so that the forecasts make the boss happy.

Although only the cat can make predictions for the market based on the colors of the markers in the sales department.

Comments

  • script.js
JavaScript
var red = 1; var yellow = 2; var green = 3; 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

Let’s correct the forecasting program.

  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.