可以啊,比如一个收款小程序
/*** var price //商品单价
* var num //商品数量
* var receive //收款金额
*/
function cashier(price, num, receive){
var sum //商品总额
var out //应找金额
if((price*num)>500){
sum=price*num*0.8
}
if(receive<sum){
out="金额不足"
}else{
out=receive-sum
}
return "商品总额:"+sum+" 收款金额:"+receive+" 应找金额:"+out
}
/*** var price //商品单价
* var num //商品数量
* var receive //收款金额
*/
function cashier(price, num, receive){
var sum //商品总额
var out //应找金额
if((price*num)>500){
sum=price*num*0.8
}
if(receive<sum){
out="金额不足"
}else{
out=receive-sum
}
return "商品总额:"+sum+" 收款金额:"+receive+" 应找金额:"+out
}