获取函数的输出语句 [英] Getting an output statement for a function

查看:68
本文介绍了获取函数的输出语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个函数的输出.此功能必须返回周薪.我认为我的功能部分是我需要的,我想不出一个警告来说明工资是多少.我需要它能够根据提示中的小时数和费率来计算常规工资或加班工资.我可以使提示正常工作,但是我尝试的每条警报声明要么没有给出周薪,要么没有计算出周薪,我无法得到它来计算加班费.
这是我到目前为止的内容:

I need an output for a function. This function has to return weekly pay. I think I have the function part the way I need it put I can''t figure out to do an alert stating what the pay is. I need to be able for it to calculate regular pay or overtime pay depending on the hours and rate from the prompts. I can get the prompts to work but every alert statement I tried either did not give the weekly pay or if it did calculate the pay I could not get it to calculate for overtime pay.
Here is what I have so far:

<html>
<head>
<script type="text/javascript">
function payForWeek(pay)
   {
   var regPay ;
   var overTime ;
   if (hours <=  40)
      regPay =  (hours * rate) ;
   else (hours > 40)
      overTime((hours - 40)*1.5*rate + 40*rate);
   return regPay ;
   return overTime ;
   }
var regPay;
var overTime;
hours  = prompt ("Enter your hours",  "") ;
rate  = prompt ("Enter your rate",  "") ;


</script>
</head>
</html>

推荐答案

我已经缩进了您原来的问题,并给出了答案.
最初,我对它进行缩进是因为它使它更易于阅读,但它清楚地表明了您的问题所在:如果您的代码执行了return语句,则它将离开该函数.因此,第一次返回后的任何语句都将永远不会执行.
I have indented your original question, and revealed the answer.
Originally, I indented it because it makes it easier to read, but it shows clearly what your problem is: If your code executes a return statement, it leaves the function. So any statements after the first return will never be executed.


编写三个JS函数,并像
一样在页面加载时添加它们
Write three JS Functions, and add them on page load like

<body onload="javascript:fnSaveHours();fnSaveRate();fnCalculatePay();"> 
</body>



在前两个函数中,通过提示捕获将值保存在页面中的各个隐藏变量中.最后,根据先前捕获的两个值计算薪酬.



In the first two functions, save the value in respective hidden variables in the page by capturing through prompt. In the last calculate the Pay based on two previously captured values.


这篇关于获取函数的输出语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆