How to use the same variable to subtract depending on whether or not there is another variable, jquery?

0

I am currently doing some validation and I am in this stage:

var total_pagar = 6000;
console.log("HAY QUE REALIZAR LA RESTA");
                    if (monto_ingresado){
                        let resultado = total_pagar-monto_ingresado;
                        return resultado;
                    }
                    else{
                        let resultado = total_pagar-forma_pago;
                        return resultado;
                    }

                        console.log(resultado);//No imprime nada.

                    if (parseInt(resultado)<0){
                        console.log("Monto ingresado excede al total a pagar");
                    }
                    else{
                        if (parseInt(resultado) === 0){
                            console.log("Cubre la deuda");
                        }
                        else{
                            console.log("HAY QUE LLENAR LA TABLA");
                        }
                    }

in some cases the variable monto_ingresado may come or in other cases the variable forma_pago may come for both cases the subtraction that is stored in the variable resultado must be performed and continue with the validations of if (parseInt(resultado)<0) but I can not make this subtraction.

Very grateful for the support.

    
asked by JG_GJ 16.10.2018 в 06:40
source

0 answers