-3

I am trying to use an if statement and the or || operator to test if the value of the select box option for type of room is either single King, single Double Queen, or single two twins and then execute some code. I keep getting the message "uncaught syntax error unidentified token ||" right where the || operator is in the if statement.

var hotel = {
 name:"Benson hotel",
 rooms:500,
 jsuites:10,
 ssuites:10,
 booked:100,
 checkAvailability: function(){
 return this.rooms - this.booked;
}
      
};

hotel.name = "Bonton";

var elName = document.getElementById("hotelN");
elName.textContent = hotel.name;


 function checkin(){
  var nRooms = document.getElementById("numRooms").value * 1;
  var tRoom = document.getElementById("typeRoom");
  if (tRoom.value = "singleK")||(tRoom.value ="singleQ")||(tRoom.value = "singleT") { //*I am getting the following message about above line of code in the console. "uncaught syntax error unidentified token ||" Obviously the above if statement with || operator is not correct//
   
   hotel.booked = numRooms + hotel.booked;
  
   if hotel.checkAvailability() < 0 {
    var rAvail = nRooms + (hotel.checkAvailability());
    if rAvail <= 0 {
     var noSay = document.getElementById("say");
     noSay.textContent = "We have no rooms available";
            }
          
             else {
              var yesSay = document.getElementById("say");
             yesSay.textContent = "We have" + rAvail + "rooms available";
         
          }

       }
<body>
    <div id="wrapper">
  <div id="heading">
   <h1 id="hotelN"></h1>
        /div>
  <div id="main">
   <form id="myForm">
   <fieldset>
   <legend>Book a Room</legend><p>
   <label for="rm1">Number of Rooms:</label> 
            <input type="number" max="10" min="1" value="1"name="rm" id="numRooms">
            Type of room: <select type="text" maxlength="14" id="typeRoom">
  <option value="singleK">Single King Bed</option>
  <option value="singleQ">Single Queen Bed</option>
  <option value="singleT">Single Two Twins</option>
  <option value="jsuite">Junior One Bedroom Suite</option>
  <option value="srsuite">Senior Two Bedroom Suite</option>
</select></p>
            Occupancy:<select type="text">
            <option>One adult</option>
            <option>Two adults</option>
            <option>One adult and Child</option>

            </select>
            
            Check In Date: <input type="date"name="checkin" id="cInDate">
            Check Out Date: <input type="date" name="checkout" id="cOutDate">          
            <button  type="button" onclick="checkin()">Submit</button>
</fieldset>
   </form>
   <H1 class="al">Hotel Room Availability</H1>
      <p class="al" ><span id="say"></span> and check out on July <span  id="dateOut"></span></p>
   
            
  
  <p id="first">jjjj</p>
        
  <p id="second"></p>

  </div> 
</div>
  • 2
    `if hotel.checkAvailability() < 0` - in your actual code or paste error? All conditions need to be wrapped in parens. – tymeJV Aug 03 '16 at 18:55
  • There's also an error on `if rAvail <= 0`. Needs parentheses: `if (rAvail <= 0)` – 4castle Aug 03 '16 at 19:00

4 Answers4

4

You just have to add a pair of parenthesis:

if ((tRoom.value == "singleK")||(tRoom.value =="singleQ")||(tRoom.value == "singleT")){
...
}

Or

if (tRoom.value == "singleK"||tRoom.value =="singleQ"||tRoom.value == "singleT"){
...
}
David H.
  • 507
  • 2
  • 10
0

The entire condition section of your if statement must be wrapped in parentheses. By doing if (condition1) || (condition2), you're terminating the conditions before your ||.

It would be like this instead: if ((condition1) || (condition2))

Additionally: The conditional operator you're looking for is ==, not =. == is used to compare two values, whereas = is used to set.

Tyler Roper
  • 21,445
  • 6
  • 33
  • 56
0
if (tRoom.value = "singleK")||(tRoom.value ="singleQ")||(tRoom.value = "singleT") {

You CANT close if() before ||

if (tRoom.value = "singleK" || tRoom.value ="singleQ" || tRoom.value = "singleT") {
Dave
  • 2,764
  • 2
  • 15
  • 27
0

You have at least 2 issues with that line:

  1. Your main issue is that you're missing a set of brackets around the whole of the condition:

    if ((tRoom.value = "singleK") || ...) {

Right now your or-operator is just floating.

  1. You need to use === to do comparisons. = is used to assign.
Carcigenicate
  • 43,494
  • 9
  • 68
  • 117