javascript adobe 中的基本算术语法错误
javascript syntax error on basic arithmatic in adobe
我只是想创建一个基本的文档级函数,它接受 2 个值和 returns 差值。我在包含 (cEnd - cStart) / msPerDay 的行中不断收到语法错误,无论它在哪里。我试过创建一个新变量 var diff = (cEnd - cStart) / msPerDay;
并且我试过以不同的方式调用 cEnd 和 cStart。我什至只是尝试了 (x + y) / c,但仍然出现语法错误。我想也许我需要声明 cEnd 和 cStart 是变量,但这也没有用。我想也许我称 if 语句错误,但它看起来也是正确的,所以我不确定这有什么问题:
function fDays(cEnd, cStart){
/* 24 h/d * 60 m/h * 60 s/m * 1000 ms/s) */
var msPerDay = 24 * 60 * 60 * 1000;
if (cEnd == null || cStart == null) {
return 0;
else {
return (cEnd - cStart) / msPerDay;
}
}
错误在 if / else 语法中,语法应该是这样的:
if (cEnd == null || cStart == null) {
return 0;
} else {
return (cEnd - cStart) / msPerDay;
}
所以整个代码将是:
function fDays(cEnd, cStart){
/* 24 h/d * 60 m/h * 60 s/m * 1000 ms/s) */
var msPerDay = 24 * 60 * 60 * 1000;
if (cEnd == null || cStart == null) {
return 0;
}else {
return (cEnd - cStart) / msPerDay;
}
}
我只是想创建一个基本的文档级函数,它接受 2 个值和 returns 差值。我在包含 (cEnd - cStart) / msPerDay 的行中不断收到语法错误,无论它在哪里。我试过创建一个新变量 var diff = (cEnd - cStart) / msPerDay;
并且我试过以不同的方式调用 cEnd 和 cStart。我什至只是尝试了 (x + y) / c,但仍然出现语法错误。我想也许我需要声明 cEnd 和 cStart 是变量,但这也没有用。我想也许我称 if 语句错误,但它看起来也是正确的,所以我不确定这有什么问题:
function fDays(cEnd, cStart){
/* 24 h/d * 60 m/h * 60 s/m * 1000 ms/s) */
var msPerDay = 24 * 60 * 60 * 1000;
if (cEnd == null || cStart == null) {
return 0;
else {
return (cEnd - cStart) / msPerDay;
}
}
错误在 if / else 语法中,语法应该是这样的:
if (cEnd == null || cStart == null) {
return 0;
} else {
return (cEnd - cStart) / msPerDay;
}
所以整个代码将是:
function fDays(cEnd, cStart){
/* 24 h/d * 60 m/h * 60 s/m * 1000 ms/s) */
var msPerDay = 24 * 60 * 60 * 1000;
if (cEnd == null || cStart == null) {
return 0;
}else {
return (cEnd - cStart) / msPerDay;
}
}