我最近开始学习HTML和JavaScript,并且正在用Notepad++创建一个简单的视频租赁脚本。创建脚本后,它无法在任何浏览器中本地执行。我很好奇哪些部分可能被不当使用,或者如果我完全遗漏了什么,谢谢。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
var name = window.prompt("Hello, what is your name?");
var choice = window.prompt("DVD or Blu-Ray?");
var days = parseInt(window.prompt("How many days are you renting for?"));
if (choice == "DVD") {
double dvdcst = 2.99;
double dvdtot = dvdcst * days;
document.write("Name: " + name "<br />"
"Days renting: " + days + "<br />"
"Cost per day: " + dvdcst + "<br />"
"Total cost: " + dvdtot + "<br />");
} else if (choice == "Blu-Ray") {
double blucst = 3.99;
double blutot = blucst * days;
document.write("Name: " + name + "<br />"
"Days renting: " + days + "<br />"
"Cost per day: " + blucst + "<br />"
"Total cost: " + blutot + "<br />");
}
</script>
</body>
</html>
发布于 2017-04-25 05:41:44
在第20行添加name和"<br />"时,您忘记了一个,然后,当使用新行进行格式化时,您还需要使用+。
此外,double也不是Javascript中存在的东西。您可以仅使用var (对于局部作用域)或不带前缀来定义变量。
请尝试以下操作
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
var name = window.prompt("Hello, what is your name?");
var choice = window.prompt("DVD or Blu-Ray?");
var days = parseInt(window.prompt("How many days are you renting for?"));
if (choice == "DVD")
{
dvdcst = 2.99;
dvdtot = dvdcst * days;
document.write("Name: " + name + "<br />"+
"Days renting: " + days + "<br />"+
"Cost per day: " + dvdcst + "<br />"+
"Total cost: " + dvdtot + "<br />");
}
else if (choice == "Blu-Ray")
{
blucst = 3.99;
blutot = blucst * days;
document.write("Name: " + name + "<br />"+
"Days renting: " + days + "<br />"+
"Cost per day: " + blucst + "<br />"+
"Total cost: " + blutot + "<br />");
}
</script>
</body>
</html>https://stackoverflow.com/questions/43598120
复制相似问题