Need help with syntax for damage formula

Im trying to make a formula using Yanfly Skill Core that checks if enemy has a specific state then has a 25% chance to proc to add another state. Here's what I have and it won't work

<Post-Damage Eval>
ChanceRate = .25;
if (b.result().isHit()) {
if b.isStateAffected(27) && if Math.random() < ChanceRate {
b.addState(8);
}
}
</Post-Damage Eval>

Heres the error I get in the debug:
SyntaxError: Unexpected identifier {stack: (...), message: "Unexpected identifier"}message: "Unexpected identifier"stack: (...)get stack: function () { [native code] }set stack: function () { [native code] }__proto__: Error
2 things:
  • Missing variable identifier when declaring the chance rate
  • Missing parenthesis in "if" statements
Code:
<Post-Damage Eval>
var ChanceRate = .25;
if (b.result().isHit()) {
    if (b.isStateAffected(27) && Math.random() < ChanceRate) {
        b.addState(8);
    }
}
</Post-Damage Eval>
2 things:
  • Missing variable identifier when declaring the chance rate
  • Missing parenthesis in "if" statements
Code:
<Post-Damage Eval>
var ChanceRate = .25;
if (b.result().isHit()) {
    if (b.isStateAffected(27)) && if (Math.random() < ChanceRate) {
        b.addState(8);
    }
}
</Post-Damage Eval>

Its giving me SyntaxError: Unexpected token &&
You also had an unnecessary "if" that I didn't see at first, edited my response.

Some helpful links:
IF statement definition
&& operator syntax
You also had an unnecessary "if" that I didn't see at first, edited my response.

Some helpful links:
IF statement definition
&& operator syntax

It works and thank you!

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-syntax-for-damage-formula.96701/