Code won't print in my console log. Why? I am trying to print things from a dataset but it won't print for some reason.
function totalPassengers(airportName) {
var airport = getColumn("Busiest Airports", "Airport");
var passengers = getColumn("Busiest Airports", "Total Passengers");
for (var i = 0; i < airport.length; i++) {
if (airport[i] == (airport[i] == airportName) ) {
return passengers[i];
}
}
}
console.log("The amount of passengers in this airport was: "+ getProperty("text_input1", "text") + totalPassengers());
function airport(airportName) {
var airports = getColumn("Busiest Airports", "Airport Code");
for (var i = 0; i < airports.length; i++) {
if (airport[i] == airportName) {
return (airports[i]);
}
}
}
console.log("The code of this airport is: " + airport);
Not quite enough data from the code right now, but we can probably assume that the totalPassengers function should return the number of passengers at a certain airport.
I advise you to pay attention to the if condition. Because the condition if (airport[i] == (airport[i] == airportName)) is probably not correct, I think it should be something like if (airport[i] === airportName).
It seems to me that the first function should be like this:
function totalPassengers(airportName) {
const airport = getColumn("Busiest Airports", "Airport");
const passengers = getColumn("Busiest Airports", "Total Passengers");
for (let i = 0; i < airport.length; i++) {
if (airport[i] === airportName) {
return passengers[i];
}
}
}
console.log(totalPassangers("NAME OF THE AIRPORT"));
As for the last line with console.log, you forgot to add the closing brackets and the argument.
console.log("The code of this airport is: " + airport("NAME OF THE AIRPORT"));