Javascript未在CMD中执行

时间:2016-10-27 00:37:25

标签: javascript

我在完成家庭作业时遇到了麻烦,我已尽最大努力编写程序。但是,我无法在桌面上使用CMD或NODE程序运行代码,有人可以告诉我我做错了什么吗?此外,我将程序保存到我的桌面而不是文件夹,这可能是问题吗?

家庭作业问题:编写一个名为pay.js的程序,计算并显示员工本周的总工资。工作周的正常工作时间为40小时,超过40小时的工作时间被视为加班。员工正常工作时间每小时18.25美元,加班时间每小时27.78美元。这名员工本周工作了50个小时。显示结果。

**

  • 我的代码

**

/*
This program will calculate an hourly employees total wages when working 40hrs, not to mention, if the the employee were to work ten hours of overtime.

input:
employee works 40hrs a week
employee hourly wage is $18.25
employee overtime wage is $27.78
employee worked 10hrs of overtime

output: 
standardhours + tenhoursofovertime

*/

var hoursperWeek = 40;
var hourlywage = 18.25;
var overtimewage = 27.78;
var overtimehoursWorked = 10;

var regularpay = hoursperWeek * hourlywage;
var overtimepay = overtimehoursWorked * overtimewage;
var regpayplusovertime = regularpay * overtimepay;

console.log(regpayplusovertime);

1 个答案:

答案 0 :(得分:0)

var totalHours = 50;
var overtimeUpper = 40;

var regularWage = 18.25;
var overtimeWage = 27.78;

if(totalHours > overtimeUpper){
    var regularHours = overtimeUpper;
    var overtime = totalHours - overtimeUpper;
    var regularHoursWage = regularHours * regularWage;
    var overtimeHoursWage = overtime * overtimeWage;
    var totalWage = regularHoursWage + overtimeHoursWage;
    console.log(totalWage);
}