Jump to content

adventurouscoderr

Members
  • Posts

    1
  • Joined

  • Last visited

adventurouscoderr's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Hello everyone, I've been studying programming over the summer. I've been reading the the head first books javascript programming to learn javascript if anyone is familiar with the book. I need help figuring out how this code works. The book shows an example of multple properties and a function together like this <!doctype html><html lang="en"><head><title>Prequalifcation</title><meta charset="utf-8"><script>var chevy = { make: "Chevy", model: "Bel Air", year: 1957, color: "red", passengers: 2, convertible: false, mileage: 1021};var fiat = { make: "Fiat", model: "500", year: 1957, color: "Medium Blue", passengers: 2, convertible: false, mileage: 88000};var cadi = { make: "GM", model: "Cadillac", year: 1955, color: "tan", passengers: 5, convertible: false, mileage: 12892};var taxi = { make: "WebVille Motors", model: "Taxi", year: 1955, color: "yellow", passengers: 4, convertible: false, mileage: 281341};function prequal(car) { if (car.mileage > 10000) { return false; } else if (car.year > 1960) { return false; } return true;}var worthALook = prequal(taxi);if (worthALook) { console.log("You gotta check out this " + taxi.make + " " + taxi.model);} else { console.log("You should really pass on the " + taxi.make + " " + taxi.model);}//// add a function to make it easier to generate the console output!//function isWorthALook(didQualify, car) { if (didQualify) { console.log("You gotta check out this " + car.make + " " + car.model); } else { console.log("You should really pass on the " + car.make + " " + car.model); }}isWorthALook(prequal(taxi), taxi);isWorthALook(prequal(cadi), cadi);isWorthALook(prequal(chevy), chevy);isWorthALook(prequal(fiat), fiat);</script></head><body></body></html> I know the code works, but how does it work? I understand the variable prequal is getting passed an agruement from the taxi Object. Then the prequal function is called which then the agruement is passed to the taxi parameter and does its magic. Then the worthALook is passed onto the if loop and the info is passed onto the console. Where I get confused at is the isWorthALook function and is isWorthALook calls below it. Does the prequal inside the parethesis of the isWorthALook have to do anything with the var prequal? How does this code work? Any help is appreciated.
×
×
  • Create New...