地图方向HTML和JS



我正在尝试用这个脚本制作一个商场的地图:

<!DOCTYPE html>
<html>
<head>
<title>Display Message</title>
<script>
// (B) CONFIRM
function demoA() {
let sgl = 'Target';
sgl;
var destination1 = prompt("Enter Your Destination", " ");
if (destination1 = sgl) {
return true
var location2 = prompt("Enter Your Closest Store", " ")
alert("Starting Directions to " + destination1)
} else {
return false
}
}
</script>
</head>
<body>
<!-- (D) TEST BUTTONS -->
<input type="button" value="Directions" onclick="demoA()" />
</body>
</html>

但是,当我运行这个时,对于destination1变量,我输入Target但它没有问我最近的商店。另一个问题是我试图使用商店名称的字符串,但我不能让它工作。

条件应为

if (destination1 === sgl) 

if (destination1 = sgl) 

这行之后还有:

return true

和你的函数完成执行在那里(不会到达下一行)

在第二次调用prompt之前从函数返回:

let sgl = 'Target';
sgl;
var destination1 = prompt("Enter Your Destination", " ");
if (destination1 === sgl) {
return true // this returns from the function and no following code is run
var location2 = prompt("Enter Your Closest Store", " ") // never runs
alert("Starting Directions to "+destination1) // never runs
// put your return here to run the above
} else {
return false
}
}

编辑:好消息!多亏了@munleashed和@Tom,我才成功了!这里是那些需要它的人的新代码!

<!DOCTYPE html>
<html>
<head>
<title>Display Message</title>
<script>
// (B) CONFIRM
function demoA () {
let sgl = 'Target';
sgl;
var destination1 = prompt("Enter Your Destination", " ");
if (destination1 === sgl) {
var location2 = prompt("Enter Your Closest Store", " ") // never runs
alert("Starting Directions to "+destination1) // never runs
return true
// put your return here to run the above
} else {
return false
}
}
</script>
</head>
<body>
<!-- (D) TEST BUTTONS -->
<input type="button" value="Directions" onclick="demoA()"/>
</body>
</html>

相关内容

  • 没有找到相关文章

最新更新