也许删除一些逻辑运算符,制作“检查功能”?还是将一些逻辑连接在一起?// 功能function getTicketPrice(childNumber,adultNumber){ if (childNumber > 2 && adultNumber > 2) { return "-"; } if (childNumber == 2 && adultNumber == 3) { return "-"; } if (childNumber == 3 && adultNumber == 2) { return "-"; } var sheet = SpreadsheetApp.openByUrl(url).getSheetByName("Ticket"); var row = getTicketPriceChild(childNumber, sheet); var col = getTicketPriceAdult(adultNumber, sheet); if (row >-1 && col === undefined) { return "-"; } if (row === undefined && col >-1) { return "-"; } var value = sheet.getRange(row, col).getValue(); if(value > 1){ return value; } else { return '-'; }}
1 回答
HUWWW
TA贡献1874条经验 获得超12个赞
像这样的东西:
function getTicketPrice(childNumber, adultNumber) {
if ((childNumber > 2 && adultNumber > 2) || (childNumber == 2 && adultNumber == 3) || (childNumber == 3 && adultNumber == 2))
return "-";
const sheet = SpreadsheetApp.openByUrl(url).getSheetByName('Ticket');
const row = getTicketPriceChild(childNumber, sheet);
const col = getTicketPriceAdult(adultNumber, sheet);
if ((row > -1 && col === undefined) || (row === undefined && col > -1))
return "-";
const value = sheet.getRange(row, col).getValue();
return value > 1 ? value : "-"
}
添加回答
举报
0/150
提交
取消