The Ternary Operator ET If & Else

The Ternary Operator ET If & Else

Thinking of putting conditions, commands, instructions etc. in your code, the conditional statements and Ternary operators are your plug.

We have multiple conditional/control structures, although my, focus is on the If & Else Statement and Ternary operator.

Assumption
I want to buy a phone that cost the sum of N50,000 , but I have only N45,000 and I want to check if I can successfully purchase that product.

code below⬇️⬇️ image.png

Alternatively, using the Ternary Operator
code below ⬇️⬇️

image.png

I prefer using the "if else statement" because it is easy to read and understand. Anyone without a little or no knowledge of programming can basically understand the lines of code and one can express his/herself while writing it, rather than the "ternary operator" which can easily be written in one line of code.

Which do you prefer? I’ll love to hear yours!😉