if文とor ||を使用しようとしています。部屋のタイプの選択ボックスオプションの値がシングルキング、シングルダブルクイーン、またはシングルツインのいずれかであるかどうかをテストしてから、いくつかのコードを実行します。私は、メッセージ "uncaught構文エラーの不明なトークンを取得し続ける| |"右のところで||演算子はif文の中にあります。javascriptでOr演算子を使用する方法
var hotel = {
\t name:"Benson hotel",
\t rooms:500,
\t jsuites:10,
\t ssuites:10,
\t booked:100,
\t checkAvailability: function(){
\t return this.rooms - this.booked;
}
};
hotel.name = "Bonton";
var elName = document.getElementById("hotelN");
elName.textContent = hotel.name;
function checkin(){
\t var nRooms = document.getElementById("numRooms").value * 1;
\t var tRoom = document.getElementById("typeRoom");
\t 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//
\t \t
\t \t hotel.booked = numRooms + hotel.booked;
\t
\t \t if hotel.checkAvailability() < 0 {
\t \t \t var rAvail = nRooms + (hotel.checkAvailability());
\t \t \t if rAvail <= 0 {
\t \t \t \t var noSay = document.getElementById("say");
\t \t \t \t noSay.textContent = "We have no rooms available";
}
else {
\t var yesSay = document.getElementById("say");
\t yesSay.textContent = "We have" + rAvail + "rooms available";
\t \t }
\t \t }
<body>
\t <div id="wrapper">
\t \t <div id="heading">
\t \t \t <h1 id="hotelN"></h1>
/div>
\t \t <div id="main">
\t \t \t <form id="myForm">
\t \t \t <fieldset>
\t \t \t <legend>Book a Room</legend><p>
\t \t \t <label for="rm1">Number of Rooms:</label> \t
<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>
\t \t \t </form>
\t \t \t <H1 class="al">Hotel Room Availability</H1>
\t \t <p class="al" ><span id="say"></span> and check out on July <span id="dateOut"></span></p>
\t \t \t
\t \t
\t \t <p id="first">jjjj</p>
\t \t <p id="second"></p>
\t \t </div> \t
</div>
if hotel.checkAvailability()<0' - 実際のコードやペーストエラーでは?すべての条件を括弧で囲む必要があります。 – tymeJV
もし 'if rAvail <= 0'にもエラーがあります。括弧が必要: 'if(rAvail <= 0) ' – 4castle