[ Prev ]
2022-11-07

-- Nov 2 In-Class Exercise Thread
function trip(departure_city, destination_city, date) {
    this.departure_city = departure_city;
    this.destination_city = destination_city;
    this.date = date;
    trip.prototype.prettyPrint = function() {
        console.log("Departure city: " + departure_city);
        console.log("Destination city: " + destination_city);
        console.log("Date: " + date);
    }
}
var t = new trip("San Jose", "Los Angeles", "2022-12-01") t.prettyPrint();
Output: Departure city: San Jose Destination city: Los Angeles Date: 2022-12-01
function trip(departure_city, destination_city, date) { this.departure_city = departure_city; this.destination_city = destination_city; this.date = date; trip.prototype.prettyPrint = function() { console.log("Departure city: " + departure_city); console.log("Destination city: " + destination_city); console.log("Date: " + date); } } var t = new trip("San Jose", "Los Angeles", "2022-12-01") t.prettyPrint(); Output: Departure city: San Jose Destination city: Los Angeles Date: 2022-12-01

-- Nov 2 In-Class Exercise Thread
<script>
      function trip(departure_city, destrination_city, data)
      {
        this.departure_city = departure_city;
        this.destrination_city = destrination_city;
        this.data= data;
        trip.prototype.prettyPrint = () =>
        {
          console.log("DEPARTURE CITY: " + this.departure_city);
          console.log("DESTINATION CITY: " + this.destrination_city);
          console.log("DATE: " + this.data);
        }
      }
      var trip = new trip("San jose", "LA","11/1/2022");
      trip.prettyPrint();
    </script>
<script> function trip(departure_city, destrination_city, data) { this.departure_city = departure_city; this.destrination_city = destrination_city; this.data= data; trip.prototype.prettyPrint = () => { console.log("DEPARTURE CITY: " + this.departure_city); console.log("DESTINATION CITY: " + this.destrination_city); console.log("DATE: " + this.data); } } var trip = new trip("San jose", "LA","11/1/2022"); trip.prettyPrint(); </script>

-- Nov 2 In-Class Exercise Thread
function trip(departure_city, destination_city, date) {
    this.departure_city = departure_city;
    this.destination_city = destination_city;
    this.date = date;
    trip.prototype.prettyPrint = function() {
        console.log("Departure City: " + this.departure_city);
        console.log("Destination City: " + this.destination_city);
        console.log("Date: " + this.date);
    }
}
let newTrip = new trip("San Francisco", "San Diego", "11/6/2022");
newTrip.prettyPrint();
function trip(departure_city, destination_city, date) { this.departure_city = departure_city; this.destination_city = destination_city; this.date = date; trip.prototype.prettyPrint = function() { console.log("Departure City: " + this.departure_city); console.log("Destination City: " + this.destination_city); console.log("Date: " + this.date); } } let newTrip = new trip("San Francisco", "San Diego", "11/6/2022"); newTrip.prettyPrint();

-- Nov 2 In-Class Exercise Thread
function trip(departure_city, destination_city, date) {
    this.departure_city = departure_city;
    this.destination_city = destination_city;
    this.date = date;
    trip.prototype.prettyPrint = function() {
        console.log("Departure City: " + this.departure_city);
        console.log("Destination City:", + this.destination_city);
        console.log("Date: " + this.date);
    }
}
var my_trip = new trip("San Jose", "Honolulu", "11/7/22");
my_trip.prettyPrint();
function trip(departure_city, destination_city, date) { this.departure_city = departure_city; this.destination_city = destination_city; this.date = date; trip.prototype.prettyPrint = function() { console.log("Departure City: " + this.departure_city); console.log("Destination City:", + this.destination_city); console.log("Date: " + this.date); } } var my_trip = new trip("San Jose", "Honolulu", "11/7/22"); my_trip.prettyPrint();

-- Nov 2 In-Class Exercise Thread
 function trip(departure, destination, date) {
    this.departure = departure;
    this.destination = destination;
    this.date = date;
    trip.prototype.prettyPrint =() => {
        console.log("Departure City: " + this.departure);
        console.log("Destination City:", + this.destination);
        console.log("Date: " + this.date);
    }
}
 var trip = new trip("Indore", "Bhopal", "4/20/01");
 trip.prettyPrint();
(Edited: 2022-11-07)
function trip(departure, destination, date) { this.departure = departure; this.destination = destination; this.date = date; trip.prototype.prettyPrint =() => { console.log("Departure City: " + this.departure); console.log("Destination City:", + this.destination); console.log("Date: " + this.date); } } var trip = new trip("Indore", "Bhopal", "4/20/01"); trip.prettyPrint();

-- Nov 2 In-Class Exercise Thread
// code
function Trip(fromCity, toCity, tripDate) {
    this.fromCity = fromCity;
    this.toCity = toCity;
    this.tripDate = tripDate;
    Trip.prototype.prettyPrint = () => {
        if (fromCity && toCity && tripDate) {
            return `Traveling from ${fromCity} to ${toCity} on date ${tripDate}.`;
        } else {
            return `Could not pretty print the object.`;
        }
        
    }
}
// test
let test = new Trip("Kailua-Kona", "San Jose", "December 29, 2022"); console.log(test.prettyPrint());
// returns --> Traveling from Kailua-Kona to San Jose on date December 29, 2022.
(Edited: 2022-11-07)
// code function Trip(fromCity, toCity, tripDate) { this.fromCity = fromCity; this.toCity = toCity; this.tripDate = tripDate; Trip.prototype.prettyPrint = () => { if (fromCity && toCity && tripDate) { return @BT@Traveling from ${fromCity} to ${toCity} on date ${tripDate}.@BT@; } else { return @BT@Could not pretty print the object.@BT@; } } } // test let test = new Trip("Kailua-Kona", "San Jose", "December 29, 2022"); console.log(test.prettyPrint()); // returns --> Traveling from Kailua-Kona to San Jose on date December 29, 2022.

-- Nov 2 In-Class Exercise Thread
function trip (departure_city, destination_city, date) {
    this.departure_city = departure_city;
    this.destination_city = destination_city;
    this.date = date;
    trip.prototype.prettyPrint = () => {
        console.log("City: ", this.departure_city);
        console.log("Destination: ", this.destination_city);
        console.log("Date: ", this.date); 
    }
}
 var trip = new trip("San Jose", "LA", "Nov 2");
trip.prettyPrint();
function trip (departure_city, destination_city, date) { this.departure_city = departure_city; this.destination_city = destination_city; this.date = date; trip.prototype.prettyPrint = () => { console.log("City: ", this.departure_city); console.log("Destination: ", this.destination_city); console.log("Date: ", this.date); } } var trip = new trip("San Jose", "LA", "Nov 2"); trip.prettyPrint();
X