【发布时间】:2015-09-14 00:57:52
【问题描述】:
我在这一行遇到了一个意外的标识符错误:
If userInput <= 7
我真的是新手,我不明白这意味着什么。我是 javascript 新手,但我正在学习。我不知道还能说什么,因为我的编程知识一点都不好。
<html>
<body>
<script type="text/javascript">
// Declare Constants and Variables
var stateTax;
var userInput;
var finalTax;
var BR = "</br >"; // Line break
var ES = " "; // Empty string
// Welcome user
document.write("Welcome to Sales Tax Calculator" + BR);
document.write("This program calculates sales tax");
document.write("under $1.00");
// take user input
userInput = Prompt("Please enter a number(Cents)" + ES);
// call selection structure
If userInput <= 7 then
stateTax = 0;
else if userInput <= 21 then
stateTax = 1;
else if userInput <= 35 then
stateTax = 2 ;
else if userInput <= 49 then
stateTax = 3;
else if userInput <= 64 then
stateTax = 4;
else if userInput <= 78 then
stateTax = 5;
else if userInput <= 92 then
stateTax = 6;
else if userInput <= 99 then
stateTax = 7;
else if userInput > 99 then
document.write("Error, Please enter a value less than 99!");
end if
// Calculate and Display sales tax
finalTax = userInput * stateTax;
document.write("Sales tax equals: " + finalTax);
document.write("Thank you for using tax calculator");
</script>
</body>
</html>
【问题讨论】:
-
您在条件语句周围缺少括号。另见developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
-
你有一个大写如果。此外,如果构造不正确。 stackoverflow.com/questions/4005614/elseif-syntax-in-javascript
-
这几乎不是 JavaScript。这个脚本有很多很多错误。你需要好好学习语言:JavaScript Guide
-
var BR = ""; =
,语法有问题...