0

Does anyone know how to add conditions to variables in JavaScript.

For example, I want to say "If X is less than 15 then it is 25" or "If Y is more than 6 it is 9". something like that. Any help is appreciated. :)

27th Aug 2017, 7:30 AM
Malik the Fox
Malik the Fox - avatar
4 Answers
0
It is known as Ternary Expression.. and ( ?: ) known as ternary operators https://code.sololearn.com/WY9cbiguRcif/?ref=app
27th Aug 2017, 8:45 AM
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ 
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ  - avatar
+ 2
if(x<15){ x=25; } if(y>6){ y=9; }
27th Aug 2017, 7:34 AM
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ 
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ  - avatar
+ 1
Yes! Thank you! That's what I meant. This really means a lot to me.
27th Aug 2017, 8:52 AM
Malik the Fox
Malik the Fox - avatar
0
Thank you. But I meant it more like I could write it like this " x = (6<7) ? 8: 12; " I saw it somewhere in the course and couldn't find it so I asked. sorry if I sound annoying. I just don't understand it and can't find it to look back and see it.
27th Aug 2017, 7:39 AM
Malik the Fox
Malik the Fox - avatar