Silver challenge: Can't fix bug when changing caffeine rating

I have not been able to fix a bug in my attempt to do the silver challenge. I finally figured out how to add both the coffee order and the caffeine strength selectors to the on method. So now I am getting my callback to run when either of those have their input changed.

But if the caffeine strength is high (starts out at 30), and you type in ‘decaf’ into the coffee order, and then reduce the strength to at most 20, I get a validation message on the coffee order. In particular, it says the strength is still 30. But when I log the value of strength it changes as it should. Moreover, the log statements show that message changes to the empty string as it should. So why am I getting a validation message in this case? Analogously, if the coffee order is already containing ‘decaf’ and you make the caffeine rating at least 20, and then delete part of the coffee order so that it does not have ‘decaf’, you get a validation message on the caffeine rating.

Given the log statements I have, I cannot see how this makes sense. Can anybody explain this behavior?

FormHandler.prototype.addCoffeeInputHandler = function(fn) {
      console.log('Setting coffee input handler for form');
      this.$formElement.on('input', '[name="coffee"], [name="strength"]' , function(event) {
        var coffee = $('[data-coffee-order="coffeeOrder"]').val();
        var strength = $('[data-coffee-order="strength"]').val();
        strength = parseInt(strength, 10);

        var message = '';
        if (fn(coffee, strength)) {
        } else {
            message = coffee + ' cannot have caffeine rating of ' + strength;
    }; // end addCoffeeInputHandler(fn)

In case this helps, if you go back (in the first senario) to the coffee order and delete ‘f’ and then add ‘f’ back (so you have ‘decaf’ again), then there is no validation message. So somehow it is then checking the updated value of strength. But the callback runs when either of the coffee order or the caffeine rating inputs change. So I don’t see why this makes a difference in the behavior. But this seems to the core of my issue.

Nevermind. I figured it out. Using''); wasn’t enough. I suppose that only applies to the input that was changing. So I added

    var coffeeSelector = document.querySelector('[data-coffee-order="coffeeOrder"]');
    var strengthSelector = document.querySelector('[data-coffee-order="strength"]') 

and then inside the if