How to set a variable as a conditional

Hello all it is nice to be here.
I will like to know how to use the let container to assign a greater than or less than value.
Example in words:

let pocketCash = less than 200
let pocketCash = greater than 200

let allowance;
if (pocketCash < 200) {
    allowance = 50;
} else 
if (pocketCash > 200) {
    allowance = 25;
} else {
    allowance = 75;

Don’t worry that it doesn’t make much sense. It’s the pattern that matters.

Thanks for trying to answer my question

what i mean is this:

let pocketCash = 200 // is a variable

now i want to know how to write [ pocketCash is less than 200 as a variable, not as an if statement ]
I dont know if you understand me

1 Like

You want a variable that represents every possible value that is less than 200? I don’t believe that is possible. I could be wrong. Anyhow, you could assign a function that returns true if the value is less than 200:

const LowOnPocketCash = cash => cash < 200;

let wallet = 150;
console.log(LowOnPocketCash(wallet)); // prints true

wallet = 210;
console.log(LowOnPocketCash(wallet)); // prints false

That is exactly what i am trying to achieve. Thanks for the help. I am a newbie, so dont mind mt questions

1 Like

You could assign every value less than 200 to an array, but what is the lower limit? There are an infinite number of values less than 200.
This would store all integers from 0 through 199:

const intsFrom0to200 = []
for (let i = 0; i < 200; i++) {

May I ask why you are trying to assign < 200 to a variable? There are likely several ways to accomplish what you have in mind, but short of assigning a string value of "less than 200" or "< 200" to your chosen variable, I don’t believe what you are asking is possible.

let lessThan200 = pocketCash < 200;
1 Like

Thanks for the answer.
Though it might not be possible, from the answers i have gotten so far, however i have learnt something too from both response.

1 Like

Logic is built on reason, and cause is built on logic. Reason stems from ideation and rationalization which is where the creative juices live. This is the area to explore first. How to get our ideas to play out. Keep a whiteboard or paper and pencil at hand to sketch your ideas. When you can get them to make sense on paper, you can begin to piece together the logic. Then you are coding.

Once the coding begins, all sorts of things begin to happen. These are all caused by our logic. Tracing and debugging are integral steps in developing reliable code. After all the weeks of putting something together, you will still be able to stand back and see that it all stemmed from the ideation stage.

Bottom line, have an idea of what you want and/or need, and draw a picture of it playing out. That picture will be worth a thousand words whence it becomes code. Logic is not learned quickly. It may come natural to some, but the majority of us have to piece it together gradually and may even trip over the same rock twice.