0

new to js here... using a bit out of necessity :-).

Why is my conditional writing "shares" to the console when the parameter(x) is writing "notionalLarge" to the console?

    console.log(x);
    if(x == 'sharesLarge' || 'sharesSmall' ) {
        console.log("shares");
    } else if (x == 'notionalLarge' || 'notionalSmall' ) {
        console.log("notional");
    } else {
        console.log("error");
    }
}```

CONSOLE:
[Log] notionalLarge (sharesOrNotional.js, line 2)
[Log] shares (sharesOrNotional.js, line 4)

1 Answers1

0

Your if condition is wrong.

The if condition will be separated into two parts:

X == 'sharesLarge'

Which is false and

'SharesSmall'

Which is equal to

'SharesSmall' != null

And this is true. So your first if condition is true.

What you want to achieve is

If(x == 'sharesLarge' || x == 'sharesSmall')
Thallius
  • 2,482
  • 2
  • 18
  • 36