I am trying to iterate through a list and pass each of the values to a function. The function works fine if I type each of the list values manually. I used console.log to ensure that cars[x] is returning proper values. The problem is at the very end with the line var worthALook......
I'm brand new to JS and I'm trying to understand what is going on.
function prequal(car){
if (car.mileage > 100000){
return false;
} else if (car.year > 1960){
return false;
}
return true;
}
let taxi = {
make: "Webville Motors",
model: "Taxi",
year: 1955,
color: "yellow",
passengers: 4,
convertible: false,
mileage: 281341
}
let cadi = {
make: "GM",
model: "Cadillac",
year: 1955,
color: "tan",
passengers: 5,
convertible: false,
mileage: 12892
}
let fiat = {
make: "Fiat",
model: "500",
year: 1977,
color: "Medium Blue",
passgengers: 2,
convertible: false,
mileage: 88000
}
let chevy = {
make: "Chevrolet",
model: "Bel Air",
year: 1957,
color: "red",
passgengers: 2,
convertible: false,
mileage: 1021
}
cars = ["taxi", "cadi", "fiat", "chevy"]
for ( x=0; x < cars.length; x++){
console.log(cars[x]);
var worthALook = prequal(cars[x]);
if (worthALook){
console.log("Your gotta check out this " + cars[x]);
}else {
console.log("You should really pass on the " + cars[x]);
}
}