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

时间:2015-04-21 20:49:09

标签: javascript

<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>

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

3 个答案:

答案 0 :(得分:1)

这不起作用:

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 :(得分:0)

  1. 当您的JS代码属于style代码时,它位于script代码内。
  2. 您的if语句写错了。条件需要在if关键字之后和括号之前的范围内。
  3. 非数字的房间应该按字母顺序排列。

答案 2 :(得分:-1)

当它提示您正在寻找的房间时,它是否需要一个字符串?在这种情况下,您可能希望if语句查找字符串。像这样:

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