function multiplyByNineFifths(number) {
return number * (9/5);
};
function getFahrenheit(celsius) {
return multiplyByNineFifths(celsius) + 32;
};
getFahrenheit(15); // Returns 59
What I don’t get about this exercise is why are we making two-step calculation for it?
Can’t I just summarise everything into one?
Eg.
function multiplyByNineFifths(number) {
The example isn’t the greatest, but breaking the program into smaller steps/separate functions can be very helpful to easier test your code and make it more readable
So - we definite a function which gives us the Count of monitors - and it does this by multiplying the columns by the rows. Makes perfect sense.
We then have a function which contains the cost of monitors, but it also requires the number of rows and columns. This makes less sense to me. We already know the number of monitors - surely the function of costOfMonitors is to take this known value and multiply it by the cost - the new information here. Why does costOfMonitors need input about the monitorCount, which it has nothing to do with?
The below works, and seems a more comprehensible solution to me:
function monitorCount(rows, columns) {
return rows*columns; //generates total number of monitors
}
let monitorCost = 200
const totalCost = monitorCount(5,4) * monitorCost;
console.log (totalCost);