Can someone check this line of js for me? Undefined error

if (user.hp / user.mhp <= 0.5) {
user.gainHP(100)
}

If I'm not mistaken, this should check if the user of a skill is at less than 50% hit points and, if they are, restore 100 hit points to them. Although, I must be mistaken, because I'm getting an error popup every time it's supposed to execute.

Any ideas?

Javascript is hard ._.
Where are you attempting to use this code at? In a script box in an event, a damage formula in a skill, or ... ?
At first I was trying to use it in a damage formula, replacing "user" with "a", but I got the same 'undefined' error.

Right now, I've got the above script running at the beginning of each turn via a State and Yanfly's Buff&State Core. A spell buff that 'tops off' a critically damaged party member throughout the fight. Neat idea, right?

I figure it's the same error and same problem either way, and didn't want to complicate my request with plugins. If the javascript runs properly, shouldn't it run properly anywhere that javascript is supposed to run? That was my thought, anyway.

Sorry if that causes confusion. If the solution would be different for each effect, I wouldn't mind knowing either one. One's better than none!
Try this:
if (user.hp / user.mhp <= 0.5) {
user.gainHp(100)
}

*gainHp (note the lowercase "p" in Hp)
Try this:
if (user.hp / user.mhp <= 0.5) {
user.gainHp(100)
}

*gainHp (note the lowercase "p" in Hp)

Oh my god...

It worked. I'm so grateful to you, yet so very upset. I feel like a moron.

So far this forum has been really nice. I hope some day I know enough about javascript that I can help people too.
No problem friend, this kind of mistake in JS it's more common than you think.

Original thread: https://forums.rpgmakerweb.com/threads/can-someone-check-this-line-of-js-for-me-undefined-error.85465/