JSFiddle - React, Tailwind, and code Playground

by tjnicolaides

JavaScript

function trainFare(zone, roundTrip, offPeakHours) {
    
    // zone 1 - 6, $1 a zone
    var baseFare = zone;
    
    // $0.50 off for roundTrip
    
    if(roundTrip) {
        baseFare = baseFare - 0.5;
    }
    
    // $0.50 off for offPeakHours

    if(offPeakHours) {
        baseFare = baseFare - 0.5;
    }

    return baseFare;
}

var trip1 = trainFare(4, true, false);

    console.log(trip1);
var trip2 = trainFare(6, false, false);
    console.log(trip2);

var trip3 = trainFare(3);
    console.log(trip3);