编写一个函数计算小费,小费为总账单的20%
<script type=text/javascript> function tip(total){ return total*0.2; }; var givetotal=prompt("总账单是多少元","")-0; if (isNaN(givetotal)){ alert("只能输出数字"); } else if(givetotal==""){ alert("不能为空"); } else{ var tip=tip(givetotal); alert("小费金额是"+tip+"元"); } </script>