zoomFactor = e.wheelDelta > 0 ? 10 : 11;
is an expression, so you can simply use that line:
F.onmousewheel = function (e) {
zoomFactor = e.wheelDelta > 0 ? 10 : 11;
};
However, if you wish to break apart the ternary expression (the ?
and :
parts), you could do the following:
F.onmousewheel = function (e) {
if (e.wheelData > 0) {
zoomFactor = 10;
} else {
zoomFactor = 11;
}
};
The ternary expression is essentially saying if e.wheelDelta is greater than 0, return 10, otherwise return 11
. The zoomFactor
variable then gets assigned that returned value. To break this out into an if/else
statement, you just have to understand the ternary syntax.
The ?
denotes the end of the boolean expression, which is e.wheelDelta > 0
. So we use that as our boolean expression for the if
statement.
The :
separates the two options, the first being the value if true, the second if false. So those become our if
and else
assignments to zoomFactor
.