Get Programming with JavaScript - Listing 6.05

Listing 6.05 - A function with three arguments

var totalCost; totalCost = function (callOutCharge, costPerHour, numberOfHours) { return callOutCharge + costPerHour * numberOfHours; }; console.log("$" + totalCost(30, 40, 3));

Further Adventures

Listing 6.05 - A function with three arguments - Task 1

var totalCost; totalCost = function (callOutCharge, costPerHour, numberOfHours) { return callOutCharge + costPerHour * numberOfHours; }; console.log("$" + totalCost(30, 40, 12)); // set numberOfHours to 12 // logs $510

Listing 6.05 - A function with three arguments - Task 2

var totalCost; // include a fourth parameter totalCost = function (callOutCharge, costPerHour, numberOfHours, discount) { return callOutCharge + costPerHour * numberOfHours; }; console.log("$" + totalCost(30, 40, 3));

Listing 6.05 - A function with three arguments - Task 3

var totalCost; totalCost = function (callOutCharge, costPerHour, numberOfHours, discount) { // apply the discount return callOutCharge + costPerHour * numberOfHours - discount; }; console.log("$" + totalCost(30, 40, 3));

Listing 6.05 - A function with three arguments - Task 4

var totalCost; totalCost = function (callOutCharge, costPerHour, numberOfHours, discount) { return callOutCharge + costPerHour * numberOfHours - discount; }; // apply a $20 discount console.log("$" + totalCost(30, 40, 3, 20));