-1

I have to create an object, three instances of objects and arrays.

Create a cruise object that has the following properties:
Cruise Date,
Cruise Destination,
Cruise Description,
Cruise URL,
Ship Name,
Ship Description,
Ship URL, Price

Make three instances of the cruise object.
Create an array of the three instances.

According to my understanding I created one cruise object with all properties mentioned and I have to create three more instances of object.

I did the following. Does creating instances means creating object of same type?

    function Cruise(cruise_Date, cruise_Destination, cruise_URL, ship_Name, ship_Description, ship_url, price ) {
        this.cruise_Date = cruise_Date;
        this.cruise_Destination = cruise_Destination;
        this.cruise_URL = cruise_URL;
        this.ship_Name = ship_Name;
        this.ship_Description = ship_Description;
        this.ship_url = ship_url;
        this.price = price
  }


    var myCruise = new cruise("16 March 2018", 

        '<a href="#">4 Night Bahmas cruise </a>', 
        "You know the name, the laid-back attitude and where to find them, but you’ll just have to visit The Bahamas to truly appreciate this classic cruise destination. On this 700-strong string of sun-splashed islands dotting the blue Atlantic, the living’s easy. (And it’s not bad on a Bahamas cruise either!) The central port of Nassau is the bustling capital of the country — bustling is a relative term, of course — while Freeport is all chill, all the time. And nothing is as delightfully desolate as Half Moon Cay and Princess Cays: pure private-destination paradise", 

        "https://www.ncl.com/cruise-destinations/bahamas-florida-cruises?cid=PS_TSI_CAL_DST_GOO-g_LEN_SRH_DESTBAF_3%20night%20bahamas%20cruise_NA_189086496943&kshid=998d4956-0345-4c42-88fb-0f1ce25bfbf9&kwid=659072&anchor=NA&gclid=Cj0KEQjw3rfOBRDJruDR8Ljm7e0BEiQAam-GsPAAXfpiBInuQfwSq6ZOe4U2KBmlRbc08kFl-gFJIBQaAtvn8P8HAQ", 

        '<a href="#">Majesty of the sea </a>', "MS Majesty of the Seas is a Sovereign-class cruise ship owned by Royal Caribbean Cruises Ltd and operated by Royal Caribbean International. ", "https://www.royalcaribbean.com/cruise-ships/majesty-of-the-seas",
        '$' + 169);  

    var myCruise2 = new cruise("Cruise_Date", "Cruise_Destination", "Cruise_Description", "Cruise_URL", "Ship_Name", "Ship_Description", "Ship_URL", "Price");

    var myCruise3 = new cruise("Cruise_Date", "Cruise_Destination", "Cruise_Description", "Cruise_URL", "Ship_Name", "Ship_Description", "Ship_URL", "Price");



    list = new Array("Departs", "Destination", "Ship", "Price from");
    instances = new Array(myCruise, myCruise2, myCruise3);

    function displayList(the_date, ) {
        // body...
    }

expected output:

enter image description here

Community
  • 1
  • 1
  • 2
    study [this](https://www.w3schools.com/js/js_objects.asp) and [this](https://stackoverflow.com/questions/15742442/declaring-array-of-objects) – wha7ever Sep 29 '17 at 21:02
  • Can you give an example of the expected output please? Thank you. – NewToJS Sep 29 '17 at 21:02
  • 1
    You executed that code? cruise is not defined anywhere also why 4 cruices if you need 3 wff – Ricardo Umpierrez Sep 29 '17 at 21:02
  • an "object" is an "instance" of a "type". So for your code (which doesn't show the code for "cruise"), "cruise" is the type...the code will be a definition of how objects get created. When you say "new cruise()" you are creating an instance. That instance is an object of type "cruise". Note that "object" is also the most generic type, so that can get a little confusing. – theGleep Sep 29 '17 at 21:16

1 Answers1

0

Your code in creating objects has a few problems. You would need to have an object constructor function named cruise() for that to work. Usually you capitalize object constructor functions. Also, I doubt they intended for you to give values of each property that are the same as the names of the properties. If you are giving an instance of an object of a cruise, you would give it an actual destination like "The Bahamas", etc. An object constructor function would look something like this:

function Cruise(date,destination,descr,url,name,price){
  this.cruiseDate = date;
  this.cruiseDestination = destination;
  this.cruiseDescription = descr;
  this.cruiseUrl = url;
  this.cruiseName = name;
  this.cruisePrice = price;
}

As for creating an array of objects, after you make the instances of the objects with actual values in them similar to how you did them, you could just put them in an array literal, unless you were supposed to do it another way.

var instances = [myCruise,myCruise2,myCruise3];