FAQ: Operators - Using Operators to Make Comparisons

This community-built FAQ covers the “Using Operators to Make Comparisons” exercise from the lesson “Operators”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn How to Code

FAQs on the exercise Using Operators to Make Comparisons

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Just a question on unknown quantity

probably overthinking but in the example given it sounds like you’re telling the computer that it == .5lbs not asking it correct?
The wording choice used is throwing me.

"We could weigh the strawberries and see if the total weight equals a half "

strawberry_weight = ?
is (strawberry_weight == .5lb)? = true

1 Like

is not recognized by the interpreter. There are no units in programming. That is something that we the programmer have to keep track of.

b === 0.5 * a    // JS comparison

will be true if b is half of a.

If i understand the code, it simply means its a built in code

But then, could there be changes to it if one has to use a different value (a different number for the weight).

Variables will vary, so we need to create arbitrary values to compare them with. If we want our variable to match a certain value, then that is what we compare it to.

I’m a little confused by the strawberry code
The way I read it if the strawberries are .5lb or greater then it’s true?
strawberry _ weight = ?
is (strawberry _ weight == .5lb)? =***>*** true
Is that what the > symbol shows =>true?

Welcome, @mcsullie_1.

Please post a link to the exercise page of this problem.

a > b   =>  a is greater than b

a >= b  =>  a is greater than or equal to b

Note that the = sign is last in two character sequence.

if (a >= 0.5) {
    // a weighs half a pound or greater
} else {
    // a weighs less than half a pound

Sorry I‘m little confused, the code is (oranges > bananas)? => false means if oranges more than bananas, it will show false. But in the directory, it said ’ If that’s false, I’ll have to add more oranges.’ I can’t figure it out…


4 > 5 ? true : false
4 + 1 === 5

5 > 5 ? true : false
5 + 1 === 6

6 > 5 ? true : false

Relational operators always return a boolean that reflects the assertion made in the comparison. We see that neither 4 nor 5 are greater than 5, so that comparison will yield false. 6 is greater than 5, so the comparison yields true.


GOT IT!!Thanks!!:grin:

1 Like

I am a bit confused about the strawberry code, which is as follows:

strawberry_weight = ?
is (strawberry_weight == .5lb)? => true

The way I interpret this is that the line of code is asking: is the strawberry weight equal to .5 lb? And then if the strawberry weight is greater than .5 lb, the answer is true. Is this correct? Perhaps I am mistaking the boolean operator (>) for an arrow.

If we are to assume the language is ES6+ (JavaScript), then,

if (strawberry_weight === 0.5) {
    // code statements

Notice that we do not include the unit (lb), only the numeric value?

Same would apply if the language is Python:

if strawberry_weight == 0.5:
    # code statements


are comparison operators. Such operations yield a boolean.

1 Like

Comparison operators are the building blocks of coding.

When playing a shooting game. Did the bullet hit the target or not.
Was there three bullets or four?
For three fall in front. For four fall at back.

The Famous Temple Run game use the same basic logic.

1 Like

@mtf :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face:

hello i have the same doubt as you, can you help me out if you got it

Try just a little bit harder, and don’t be so dependent on others to give you the answer. Read what they read and apply it to the problem, then you will likely ‘get it’, just as they did.

bananas = 5
oranges = 3

is (oranges > bananas)? => false

that ‘‘false’’ shown above are we telling it to show false if oranges > bananas, or does the computer saying the answer it’s false, if it’s saying false how can we add oranges

First off, put the computer out of your mind. It is not doing anything on its own. If it is doing anything, it is carrying out our instructions. That is the only thing a computer knows how to do.

1 Like

that ‘‘false’’ shown above are we telling it to show false if oranges > bananas

say yes or no please
iam totally new to this so sorry for asking many doubts to you