How do I add if/else based on switch in formulas

Okay, I know that this is most likely in the wrong part of the forums, but I couldn't really pinpoint where to put it, so I went to specific. Pretty sure it goes in the JS boards... But I'm not sure which, so my sincere apologies to the mods.

Anyway, I need an attack's damage formula to check if a switch is on, and swap between hitting regular defense(b.def) and magical defense(b.mdf). Character's a Mystic and can use a skill to swap it, while still retaining hitting with regular attack(a.atk)

Technical aspects of it possibly messing with other characters is already addressed with a Yanfly script replacing the regular attack in a weapon.

So, how do I do it?
$gameSwitches.value(15) ? b.def : b.mdf

will give you b.def if switch 15 is on, and b.mdf if switch 15 is off.
$gameSwitches.value(15) ? b.def : b.mdf

will give you b.def if switch 15 is on, and b.mdf if switch 15 is off.
Aye. So, example:
a.atk * 3 - $gameSwitches.value(15) ? b.def : b.mdf * 2

Is that right?
Yes. I'd put some parentheses in there for clarification:

a.atk * 3 - ($gameSwitches.value(15) ? b.def : b.mdf) * 2
Yes. I'd put some parentheses in there for clarification:

a.atk * 3 - ($gameSwitches.value(15) ? b.def : b.mdf) * 2
Thank you so much, Shaz! Works like a charm!

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-add-if-else-based-on-switch-in-formulas.104384/