一批货放在仓库里,计费方式如下:
1-7 天: 免费;
8-14 天:16/天;
15-21 天:32/天;
22-28 天:48/天;
以此类推。
首先要求是前端代码
传入的参数是天数。
例如放 15 天,费用就是 16x7+32=144
1
rabbbit 2018-06-26 10:41:52 +08:00
let price = function(day) {
if (!day && !typeof(a) === 'number') return TypeError; let amount = 0; let i = 0; while (day > 0) { day -= 7; let stepPrice = i * 16; amount += day > 0 ? stepPrice * 7 : stepPrice * (7 + day); i++; } return amount; } console.log(price(0)); console.log(price(1)); console.log(price(7)); console.log(price(8)); console.log(price(14)); console.log(price(15)); |
2
rabbbit 2018-06-26 10:45:42 +08:00 1
|
4
rabbbit 2018-06-26 11:16:47 +08:00
if (!day && !typeof(a) === 'number') return TypeError; -> if (typeof(day) !== 'number') return TypeError;
|