I am facing an issue with a switch statement in my code. The switch has multiple cases that compare values and assign a corresponding text to a variable. However, when I run the switch statement, it always executes the default case even though my condition is true. Why could this be happening?
Value:
Apartment
Code snippet:
var rental_cat = $('#rentals_type').val();
alert(rental_cat);
var rental_type = "";
switch (rental_cat) {
case (rental_cat == "Apartment"):
rental_type='daily';
alert(rental_type);
break;
case (rental_cat == "Office"):
rental_type='work_daily';
alert(rental_type);
break;
default:
rental_type='other';
alert(rental_type);
break;
}
Upon execution of the switch statement, the result always shows "other" as the output.