# FAQ: Operators - Using Operators to Get Different Outcomes

This community-built FAQ covers the “Using Operators to Get Different Outcomes” 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 Get Different Outcomes

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 () 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.

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

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!

could someone give me an example of when a NOT expression is used? I’m kinda having a hard time getting it.

does it mean that if something like NOT (2 < 7) is used in a code, the computer would identify anything equal to that as false?

sorry if I’m not getting it, this is still new to me lol

6 Likes

NOT is a boolean toggle.

``````not True  => False
not False => True
``````

That’s the direct toggle, but there is anothe aspect to booleans, truthy and falsy.

``````not truthy => False
not falsy  => True
``````

A truthy value is any non-zero number, any non-empty string, any relation that yields True, or an object such as `{}` or `[]`.

A falsy is any number equal to zero, any empty string, any relation that yields False, any undefined variable, and depending upon the language, `undefined`, `None`, `nil`, `null`, …

Since the NOT operator casts truthy to True, and falsy to False before toggling, we can double NOT as a way to cast any expression to an untoggled boolean.

`````` not not 1  => True

not not '' => False
``````

If the expression is truthy, not not expression will be True. If falsy, it will be cast to False.

8 Likes

ah okay, that makes more sense. Thank you

also I had no idea truthy and falsy were a thing. Javascript language is more colorful and fun than I realized lol

2 Likes

Yuo’re welcome.

That might not have come up yet. When it does you’ll be raring to go.

It’s actually a general programming concept that any loosely typed or moderately typed language will support. The stricter the typing, the stricter the comparisons. JS is probably the most loosely typed of them all.

There’s another rabbit hole to go down between `==` (equality) and `===` (identity) comparisons. That will be for another discussion but don’t be afraid to bring it up when you get to that point in the learning curve.

6 Likes

I am also struggling to understand the meaning of the “NOT” boolean operator. And unfortunately the explanation here isn’t helping me very much. Can anyone explain it to me in a different way?

From what I understand, the NOT operator is there to give an opposite answer of whatever value is presented.

So if 1 = True, then putting NOT before 1 makes it False and vice versa.

5 Likes

Hi, cattoren.

The ‘NOT’ Boolean operator change a value to it’s opposite.

If you have: 1 < 3 = TRUE, when you use ‘NOT’ 1 < 3 the value will change from ‘TRUE’ to ‘FALSE’, its opposite.

The same with: 2 > 10 = FALSE, if you use ‘NOT’ 2 > 10 the value ‘FALSE’ will change to ‘TRUE’, its opposite.

I hope have helped

9 Likes

This made it click! Thank you

1 Like

for recipe 2: applesauce
the question says a recipe that includes apples.
And there are 0 apples.
I think the question should use another fruit rather than an apple because if we write it in code
NOT (0 apples) it doesn’t make any sense.
the question should be like this: a recipe needs 5 oranges
and there are only 4 apples.
then we can say NOT ( 4 apples) Thank you

Hey guys. I’m in a bit of confusion with this given piece of text:

“For example, what if we only had apples in our fridge? If a recipe asked for either apples OR pears, we could still make the recipe. But if a recipe requires both apples AND pears, we wouldn’t be able to make it.”

So, my theory is: If a recipe asks for 2 pears AND 3 apples while we only have the 3 apples in our fridge, the expression would be apple (3 ≥ 3) AND pear (0 ≥ 2). So, we literally can’t proceed with this recipe, but the explanation to AND operator is: both expressions leads to true. So, although we know we can’t, the program keeps telling we can?
I hope it makes sense but it really got in my sissies.

I’m sorry but what is a toggle?

So, the operator NOT means its opposite. If I need a pair of shoes to go out (not by now) and I only found one of them, the result may be NOT whether I have a pair of shoes or just one?
In which cases I might use this operator?

Toggle is a term we can use in any situation where there are but two states. A toggle switch toggles from one source to another in an electrical circuit, or it may toggle `on` and `off`. This is known as a binary. Same with `0` and `1`. Toggling simply takes the opposite state.

``````not True   =>  False
not False  =>  True
``````

It lets us check if a state is opposite.

``````a = 1

if not a:
print ('a is 0')
else:
print ('a is 1')
``````
1 Like

why would we use NOT to change something to its opposite? like if we want something to be false, couldn’t we just make the statement false, instead of say NOT true? I’m confused why this is necessary.

5 Likes

I understand the Recipe 2 and Recipe 3, but Recipe 1 doesn’t make sense. “You have a fruit salad recipe that calls for seven apples and four oranges.” On the picture, it shows 3 apples “select” 2 oranges. How is it 3 apples “AND” 2 oranges? There aren’t enough apples or oranges for Recipe 1.

1 Like

In the instruction section, the first fruit salad recipe calls for 7 apples AND 4 oranges. However, we only have 3 apples. How does that even work; I don’t get it. Could someone help?

2 Likes