为什么这不起作用?有人可以告诉我如何正确做到这一点


<HTML>
<HEAD>
<TITLE>
Find Your Classroom
</TITLE>
<HEAD>
<BODY BGCOLOR= #CC6666>
<STYLE>
var Room = prompt(“Which Room Are You Looking For”?);
if {
   Room = [113, 111, 115, 117, 205, 211, 215, 217, 309, 313, 311, 315, 317, 321]
   console.log(“The Staircase Closest To Your Room Is Staircase A”)
};
if {
    Room = [107, Main Office, 207, 213, 202, Library, 202, 307, 205, 303]
    console.log(“The Staircase Closest To Your Room Is Staircase B”)
};
if {
   Room = [106, 104, 110, 206, 212, 210, 310, 308]
   console.log(“The Staircase Closest To Your Room Is Staircase C”)
};
if {
   Room = [112, Weight Room, Boys Locker Room, 114A, Gym 1, PE Office, Trainer Athletic Director, 312, Gym 1 Balcony, Gym 2]
   console.log(“The Staircase Closest To Your Room Is Staircase D”)
};
if {
   Room = [114, Clinic, 118, Girls Locker Room, Swimming Pool, 120, 214, 220, 218, 214, 314, 316, 318, 320]
   console.log(“The Staircase Closest To Your Room Is Staircase G”)
};
if {
   Room = [136, 134, 122, 132, 140, 222, 224, 234, 236, 238, 240, 322, 334, 324, 322A, 336, 338, 340, 342]
   console.log(“The Staircase Closest To Your Room Is Staircase H”)
};
if {
   Room = [138, 144, 146, 150, 154, 148, 242, 244, 246, 248, 250, 252, 254, 258, 260, 256, 344, 346A, 346, 348, 350, 356, 360, 358, 354, 352]
console.log(“The Staircase Closest To Your Room Is Staircase J”)
};
if {
   Room = [161, 149, 147, 145, 151, 153, 157, 155, 153A, 251, 249 247, 257A, 257, 253, 255, 261, 259, 353, 351, 349 Gym 3]
   console.log(“The Staircase Closest To Your Room Is Staircase M”)
if {
   Room = [ 143, 141, 125, 119, 123, 127, 139, 137, 243,241, 225, 221, 223, 239, 229, 345, 347, 343, 341B, 341, 339, 329, 327, 325, 323, 325]
    console.log(“The Staircase Closest To Your Room Is Staircase O”)
if {
   Room = [129, 135, 133, 130, 128, 231, 235, 233, 230, 228, 232, 226, 331, 337, 333, 335, 330, 328, 332R, 326, 332]
  console.log(“The Staircase Closest To Your Room Is Staircase Z”)
};
</STYLE>

它应该提出问题,然后让用户回答并返回最接近的楼梯。请帮忙。

不起作用:

if {
   Room = [113, 111, 115, 117, 205, 211, 215, 217, 309, 313, 311, 315, 317, 321]
   console.log(“The Staircase Closest To Your Room Is Staircase A”)
};

您可能希望:

if ([113, 111, 115, 117, 205, 211, 215, 217, 309, 313, 311, 315, 317, 321].indexOf(Room) !== -1) {
    console.log("The Staircase Closest To Your Room Is Staircase A");
}

此外,它必须在<script type="text/javascript">内部,而不是<style>

  1. 当您的 JS 代码属于 script 标签时,它位于 style 标签内。
  2. 您的 if 语句编写不正确。条件需要位于 if 关键字之后和大括号之前的括号内。
  3. 不是数字的房间应该被字符串化。

当它提示您要查找的房间时,它不会接受字符串吗?在这种情况下,您可能希望让 if 语句查找字符串。喜欢这个:

    if {
   Room = ["113", "111", "115".....(rest of them like this)]
   console.log(“The Staircase Closest To Your Room Is Staircase A”)
};

相关内容

最新更新