-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
  • 47,356
  • 86
  • 216
  • 346

3 Answers3

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

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

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
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,579
  • 1
  • 18
  • 11