Created
March 29, 2012 10:49
-
-
Save h4/2235792 to your computer and use it in GitHub Desktop.
JS. Задание Taxi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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