Simple if else with drop down menu not working

I have this code but in the console log I always see “In Prozent angegeben”, maybe define them as constant and do the if else outside of the function?
In the end the scales of a graph have to be adapted to either percentage or absolute values.

       <div id="auswahl_id" class = "auswahl_class">
        <select id="changeAxisYLabel" onChange = "update()">
            <option value ="absoluteValue">Absolute Value</option>
            <option value ="percentage">Percentage</option>
        </select>
       </div>


           function update() {
			var select = document.getElementById('changeAxisYLabel');
			var option = select.options[select.selectedIndex];

            let vv = option.value;
            let tt = option.text;
            console.log(vv);
            console.log(tt);

                if (vv = "percentage") {
                    console.log("In Prozent angegeben");
                } else if (vv = "absoluteValue") {
                    console.log("In Zahlen angegeben");
                }
            }

		    update();

= is not a comparison operator in JS, it is the assignment operator. For comparison, you usually want ===.

1 Like

Of course, I remember that was always asked for in the tests.

to check that the two operands are equal you must use (===) it’s a strict equality which returns false for the values which are not of a similar type
if (vv === “precentage”)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.