I'm sure there should be a very simple answer to this question, but at the risk of sounding silly - I can't get this switch statement to work. The input var, 'status' can be either "public" or "draft", and I can assure you that it only holds one of these two values, since I warned about this at different stages, and in any case, the if statement here works, see:
function switch_status(status){ if (status == 'public'){ return false; } if (status == 'draft') { return true; }
^ This works, but replacing "if" with this "switch" statement below does not work.
switch(status){ case 'public': return false; case 'draft': return true; } }
The first one to give me the inevitable awkwardly simple answer will receive my reward!
EDIT: Here is my complete code -
$('.status').live('click', function(){ fullClass = $(this).attr('class'); id = fullClass.split(' ').slice(-1); status = fullClass.split(' ').slice(-2,-1); var newStatus = switch_status(status); alert(newStatus); }); function switch_status(status){ // if (status == 'public'){ // return false; // } if (status == 'draft') { // return true; // } switch(status){ case 'public': return false; case 'draft': return true; } }
Inigo source share