Ruby3.12 :-Control Flow in Ruby:


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-ruby/lessons/control-flow-in-ruby/exercises/not?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
Hello Friends, I am confused by “The Not” operator in ruby. In the given problem no. 3 how does the evaluation arrives when the solution is correct.

```

boolean_1 = !true

boolean_1 = false

boolean_2 = !true && !true

boolean_2 = false

boolean_3 = !(700 / 10 == 70)

boolean_3 = false
Replace this line with your code.

<do not remove the three backticks above>

https://www.codecademy.com/courses/learn-ruby/lessons/control-flow-in-ruby/exercises/not?action=lesson_resume

#2

boolean_3 = !(700/10 == 70)
boolean_3 = !(70 == 70)
boolean_3 =!(true)
boolean_3 = !(true) = false


#3

Something to understand about NOT, !. Where AND and OR are binary operators taking two operands, NOT is a unary operator that takes only one operand, immediately to its right. The thing to consider is that no matter what that operand is, the NOT form of it will be boolean.

! (3)  =>  3 is truthy so  =>  ! (true)  =>  false

We can convert a truthy value to true with a double not

! ! ('foo')  =>  ! ! (true)  =>  ! (false)  =>  true

Bear in mind that precedence rules apply to logical operators, so…

brackets are evaluated first
NOT comes next
AND follows
OR is last

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.