#Positions of values swapped for a division in a function

3 messages · Page 1 of 1 (latest)

patent carbon
#

Hi guys, I've been at it for some time now and still can't figure out why the division function runs the formula in reverse. Given the output in console is 0.3281, it must've taken the conversion to be divided by 10...

This is the solo project - unit converter.

#

The multiplication is fine, division is the only one with this issue, and I tried conversion/ value and it worked as intended but that's not the right formula...

graceful pollen
#

The first parameter to the bind() function is used to set the this value in the function that's being bound to. (FWIW, in this case, you could actually be passing null here, as this is not used in either of the bound functions.) But the second parameter (and any parameters that might follow) are prepended to the arguments that are passed to the bound function when it is ultimately called. This means that the lengthConversion argument you are binding will actually correspond to the first parameter in the multiplication and division functions. Spoiler: ||So, basically, to get things working you just need to reverse the parameters in the function signatures for multiplication and division:

    const allConversions = {
        multiplication: function(conversion, value) {
            return value * conversion;
            
        },
        division: function(conversion, value) {
            return value / conversion;
        },
    }
```||