DEV Community

Discussion on: Daily Challenge #280 - Driving School

Collapse
 
avra profile image
Avra

Via phone, but this should work:

 function cost(min) {
   let cost = 0;
   min -= 5;
   if (min <= 0) {
     return cost;
   }
   cost += 30; // first hour
   if (min < 60) {
     return cost;
   }
   while (min > 0) {
     min -= 30;
     cost += 10;
   }
   return cost;
 }