Skip to content

Instantly share code, notes, and snippets.

@h4
Created March 29, 2012 10:49
Show Gist options
  • Save h4/2235792 to your computer and use it in GitHub Desktop.
Save h4/2235792 to your computer and use it in GitHub Desktop.
JS. Задание Taxi
function getTaxiFare(len, hour) {
var price = 200,
nightTax = 0.3;
if (len < 10) {
len = 10;
}
if (hour < 1 || hour > 24) {
return alert('В сутках только 24 часа!');
}
total = len * price;
if (hour > 6 && hour < 22) {
return total;
} else {
return total * (1 + nightTax);
}
}
function getTaxiFare(len, hour) {
var price = 200,
nightTax = 0.3;
if (isNaN(len) || isNaN(hour)) {
throw new Error("Расстояние и время должны быть числом");
}
if (hour < 1 || hour > 24) {
throw new Error("В сутках только 24 часа!");
}
if (len < 10) {
len = 10;
}
total = len * price;
if (hour > 6 && hour < 22) {
return total;
} else {
return total * (1 + nightTax);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment