Add a Conditional Logic to Your Formula
If / else statement is extremely popular in such programming language as Javascript. It lets you include logic on which something happens or doesn’t happen. Just like with all other elements, you have to hit the plus button to add the IF / Else element.
Then you have to choose the source - it can be data, parent, or a string. In this case, we will use the price we have already gotten from the page as a parameter. Then you need to choose the "mode". We will take “larger than”. And then you have to choose the data for comparison.
Let’s say, that we want to do something with the items in this list, that costs more than 20 $. Again it doesn’t have to be a number - you can get data to compare from somewhere else.
Look at the example in the video. When the IF statement is launched, the first element will be run. However - the IF / ELSE element will be on the same level as the IF statement.
Let’s take a look at how it really works - we entered, that we want to do something with the items, that cost more than 20$. This time we put the DOM action right under the IF statement and the action will click on the “Add to cart” button. OR, if the price is lower than 20 $, it will just continue the task.
Let’s run the formula. And Voila! We have 4 items in our cart!