Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (australopithecus):

What is wrong with my Java Code // add a parameter called hourOfDay to the function var taxiFare = function (milesTraveled, hourOfDay) { var baseFare = 2.50; var costPerMile = 2.00; var nightSurcharge = 0.50; // 8pm to 6am, every night var Basecost = baseFare + (costPerMile * milesTraveled); var cost = Basecost; if (hourOfDay>=6 || hourOfDay<20){ return cost; } else { // add the nightSurcharge to the cost starting at // 8pm (20) or if it is before 6am (6) return cost + nightSurcharge; } }; taxiFare(84,23);

OpenStudy (australopithecus):

My hourOfDay variable is not having its desired effect

OpenStudy (anonymous):

The problem is with this line of code: if (hourOfDay>=6 || hourOfDay<20). Suppose hourOfDay was 21 (9pm), the following expression (hourOfDay>=6 || hourOfDay<20) will evaluate to true because 21 is greater than 6 (20>=6 is true). Bottom line, this line should be like: if (hourOfDay>=6 && hourOfDay<20). Like if the hourOfDay is greater than or equal 6 AND less than 20. It should be greater than or equal 6 while at the same time it's less than 20 to have the desired effect (If not night).

OpenStudy (australopithecus):

Oh thank you :) so // add a parameter called hourOfDay to the function var taxiFare = function (milesTraveled, hourOfDay) { var baseFare = 2.50; var costPerMile = 2.00; var nightSurcharge = 0.50; // 8pm to 6am, every night var Basecost = baseFare + (costPerMile * milesTraveled); var cost = Basecost; if (hourOfDay>=6 && hourOfDay<20){ return cost; } else { // add the nightSurcharge to the cost starting at // 8pm (20) or if it is before 6am (6) return cost + nightSurcharge; } }; taxiFare(84,24);

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!