@yusaney1 has presented a solution. The solution however involves creating a custom plugin which I believe is quite a bit of overhead and work to just to add the logic you presented in your question.
Keep in mind, the entire point of using Bubble is to write as little code as necessary. In other words, try to implement as much logic as you can within the Bubble workflows.
Here is an example setup of how to use only when and get a property value from an object.
What is happening inside of that Node script box, I’ll mostly leave for you to search the forums and do some reading. However, as it pertains to this question, you will need to understand how to grab the property from your object. Bubble basically stores the properties as the field name, suffixed by the property type. So my person data type has a field named age and it is defined as a number, hence “persons.age_number”. However, if you want to be sure of the properties on your data type you can always send the properties out to a text object on your page for debugging using
Finally, you can chain these together to create the logic you need above using the "Result of previous step like this:
Hopefully this gets you on your way.