-3

I'm trying to get a condition working but not sure about the syntax...

How would I write this in jquery/javascript?

if (value.type) == 'football' then {
 //do something
} else {
  //do something else
}
Satch3000
  • 44,076
  • 86
  • 209
  • 342

3 Answers3

2
if (value.type == 'football') {
    //do something
} else {
    //do something else
}

Reference: if...else, == vs ===.

Community
  • 1
  • 1
Darin Dimitrov
  • 994,864
  • 265
  • 3,241
  • 2,902
2
if ((value.type) == 'football') {
 //do something
} 
else {
  //do something else
}

or

if (condition) {
 //do something
} 
else if(condition) {
  //do something else
}
else {
  //do something else
}
1

JS

if (value.type === 'football')
{
    //Do something
}
else
{
    //Do something else
}

or you could use the short if

message = ('value.type' === 'football') ? "type is equal to football" : "type is not equal to football";

jQuery is just a js library and it doesn't have if else implementation cause it really not needed.

Hope it helps

MacGyver
  • 6,187
  • 1
  • 17
  • 11