<!--
Problem 3:
Background:
Auto rickshaws are a very common mode of transportation in India. They are typically fitted with a meter that tracks the auto fare, based on distance traveled and waiting time (eg: when stuck in traffic jam). If it is night time, an extra charge of 50% is levied.
http://en.wikipedia.org/wiki/Auto_rickshaw#India
Problem statement:
Write a program that will compute the auto fare: it should take as arguments the distance traveled in kilometers (d), the waiting time in minutes (w), and whether it is night time (n). The assumed auto fare formula is:
20 + 8 * (d-1) + 4 * w
Add 50%, if n=true
(Please note that the above formula is make-belief! Please don't get into a fight with an auto-walla over this formula!)
Examples:
Given the kilometers traveled is 6
And the minutes spent waiting in a traffic jam is 8
And it was day time
When the end of the journey is reached
Then the meter displays the total fare as Rs 92
Given the kilometers traveled is 3.5
And the minutes spent waiting in a traffic jam is 4
And it was night time
When the end of the journey is reached
Then the meter displays the total fare as Rs 84
-->
<html>
<body>
<div>The Answer is: </div>
<div class='answer'></div>
</body>
</html>
JavaScript
// js
// helper function for output
function writeAnswer(answer) {
$('div.answer').append($('<div>').text(answer));
}
function autoFare(d, w, n) {
var answer;
var fare = 20 + 8 * (d-1) + 4 * w;
if (n) {
fare = 1.5 * fare;
}
answer = "Rs " + fare;
writeAnswer(answer);
}
autoFare(3.5, 4, true);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.