@@ -84,7 +84,7 @@ function updateRoute(route, city) {
8484
8585function routes ( departingCity , destinationCity ) {
8686 if ( departingCity === destinationCity ) {
87- throw "Destination cannot be the same as departure."
87+ throw "Destination city cannot be the same as departure city ."
8888 }
8989
9090 const possibleRoutes = [ ] ;
@@ -131,7 +131,7 @@ function shortestRoute(routes) {
131131 throw "Have to provide at least one route"
132132 } else {
133133 const currentShortestRoute = routes [ 0 ] ;
134- for ( let index = 0 ; index < routes . length - 1 ; index ++ ) {
134+ for ( let index = 1 ; index < routes . length - 1 ; index ++ ) {
135135 const route = routes [ index ] ;
136136 if ( routeLengthInKilometers ( currentShortestRoute ) < routeLengthInKilometers ( route ) ) {
137137 currentShortestRoute = route ;
@@ -143,10 +143,9 @@ function shortestRoute(routes) {
143143
144144function routeCostInEuros ( route ) {
145145 const pricePerKilometers = 0.19 ;
146- return routeLengthInKilometers ( route ) * pricePerKilometers ;
146+ routeLengthInKilometers ( route ) * pricePerKilometers ;
147147}
148148
149-
150149const amsterdamArnhemRoutes = routes ( "Amsterdam" , "Arnhem" ) ;
151150console . log ( amsterdamArnhemRoutes ) ;
152151const shortestAmsterdamArnhemRoute = shortestRoute ( amsterdamArnhemRoutes ) ;
@@ -155,5 +154,5 @@ console.log(
155154 "Our route:" ,
156155 shortestAmsterdamArnhemRoute ,
157156 "is" ,
158- routeLengthInKilometers ( shortestAmsterdamArnhemRoute ) ,
159- "km" ) ;
157+ routeLengthInKilometers ( shortestAmsterdamArnhemRoute ) + " km" ,
158+ ", costing €" + routeCostInEuros ( shortestAmsterdamArnhemRoute ) ) ;
0 commit comments