0
function calculatePrice(base_cost, base_dist, additional_cost, additional_dist, total_dist) {

  if (total_dist > base_dist) {



  } else {
     return base_cost;
  }


}

function unitTest() {
  var cost;

  cost = calculatePrice(10,20,5,5,15);
  if (cost != 10) console.log ("FAILED 1");

  cost = calculatePrice(10,10,5,5,15);
  if (cost != 15) console.log ("FAILED 2");

  cost = calculatePrice(20,10,5,1,15);
  if (cost != 45) console.log ("FAILED 3");

  cost = calculatePrice(20,10,5,1,1);
  if (cost != 20) console.log ("FAILED 4");

  cost = calculatePrice(10,10,5,1,14);
  if (cost != 30) console.log ("FAILED 5");

  cost = calculatePrice(10,10,5,2,14);
  if (cost != 20) console.log ("FAILED 6");

  console.log('Test complete');

}

I want to calculate the function value of unitTest for passing.I pass only 1 and need to write some pass code in the calculatePrice function. Thanks a lot

3
  • can you explain bit more Commented Mar 12, 2014 at 6:03
  • I want to pass all the costs value in the unitTest function Commented Mar 12, 2014 at 6:06
  • I need to write in the calcutePrice function for passing unitTest Commented Mar 12, 2014 at 6:07

1 Answer 1

2

You need to use Math.ceil

Calculation will be like that

var dist_diff = total_dist - base_dist;
var time = Math.ceil(dist_diff / additional_dist);
return (time * additional_cost) + base_cost;

So, you will got the Test complete result with no errors.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.