Skip to content

Commit 275db6a

Browse files
author
Frank Versnel
committed
More bugs added to train-station.js
1 parent a96a0a3 commit 275db6a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Debugging2/homework/train-stations-complete.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function updateRoute(route, city) {
8484

8585
function 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

144144
function routeCostInEuros(route) {
145145
const pricePerKilometers = 0.19;
146-
return routeLengthInKilometers(route) * pricePerKilometers;
146+
routeLengthInKilometers(route) * pricePerKilometers;
147147
}
148148

149-
150149
const amsterdamArnhemRoutes = routes("Amsterdam", "Arnhem");
151150
console.log(amsterdamArnhemRoutes);
152151
const 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

Comments
 (0)