jQuery if statement problem

jQuery if statement problem

Hi everyone 

I am working on my smart home project for college.

I am using jQuery to change value of the buttons however it doesn't work as desired
Whenever to floors are shown I would like to change the 3rd value (both floors) as well 

Included code

  1. $(document).ready(function() {

  2.     $("#groundfloor").click(function() {
  3.         // changing attributes of the buttons
  4.         if ($(this).text() == "Show ground floor") {
  5.             $(this).text("Hide ground floor");
  6.         }

  7.         else if ($(this).text() == "Hide ground floor") {
  8.             $(this).text("Show ground floor");
  9.         }
  10.         else {
  11.             console.log("Error");
  12.         }
  13.     });
  14.     $("#firstfloor").click(function() {
  15.         // changing attributes of the buttons
  16.         if ($(this).text() == "Show first floor") {
  17.             $(this).text("Hide first floor");
  18.         }

  19.         else if ($(this).text() == "Hide first floor") {
  20.             $(this).text("Show first floor");
  21.         }
  22.         else {
  23.             console.log("Error");
  24.         }
  25.     });
  26.     $("#bothfloor").click(function() {
  27.         // changing attributes of the buttons
  28.         if ($(this).text() == "Show both floors") {
  29.             $(this).text("Hide both floors");
  30.             $("#groundfloor").text("Hide ground floor");
  31.             $("#firstfloor").text("Hide first floor");
  32.         }

  33.         else if ($(this).text() == "Hide both floors") {
  34.             $(this).text("Show both floors");
  35.             $("#groundfloor").text("Show ground floor");
  36.             $("#firstfloor").text("Show first floor");
  37.         }
  38.         else {
  39.             console.log("Error");
  40.         }
  41.         if (("#groundfloor".text() == "Hide ground floor") && ("#firstfloor".text() == "Hide first floor")) {
  42.             $("#bothfloor").text = "Hide both floors";
  43.         }
  44.         else if (("#groundfloor".text() == "Show ground floor") && ("#firstfloor".text() == "Show first floor")) {
  45.             $("#bothfloor").text = "Show both floors";
  46.         }
  47.     });

  48. });