vendredi 7 juillet 2017

Object value not changing with JavaScript ternary operator?

I am attempting to change the value of an input into a different string, depending on if the inputed answer was "Yes" or "No". I have attempted to use ternary operators to clear up my code a little bit, but I keep getting original value ("Yes" or "No") instead of the value that the input should change into. I have the following code

        function setYesNoValue(input, yes, no){
            input = input == "Yes" ? yes : no;
        };
        logger.logConsoleAndFile('...aaaaa....')
        setYesNoValue(oneLInput, "517", "518");
        setYesNoValue(oneMInput, "518", "519");
        setYesNoValue(oneNInput, "519", "520");
        setYesNoValue(oneOInput, "520", "521");
        setYesNoValue(fourAInput, "526", "527");
        setYesNoValue(fiveJ1Input, "538", "539");
        logger.logConsoleAndFile('...bbbbb....')

The task I am attempting to perform works well when I use standard if else conditional statements, but I would like to implement this strategy to clear up the length code. What am I doing wrong? Why is the value of the input changing to the its respective parameter? I should add on that I am scripting this in a node.js file. I believe that this shouldn't be an issue, but just wanted to address this.

Aucun commentaire:

Enregistrer un commentaire