Itinerary/Ports
Itinerary/Ports
Now we can actually start incorporating our objects. We're going to create a new Itinerary
with some Port
objects inside of our HTML, and we'll use our Controller
to render all of an itinerary's ports to the screen.
## Challenge
Instantiate an Itinerary
with some Port
s inside of index.html
and loop over the itinerary's ports, rendering an element to the DOM for each one.
To complete this challenge, you will need to:
- Include in your
itinerary.js
andport.js
files intoindex.html
usingscript
tags. - In the inline
script
block, create some newPort
instances and add them to a newItinerary
instance. - Create a new
div
with the idports
nested inside theviewport
div. - In
style.css
, add a new selector for#ports
. Specify a width of0px
, amargin-top
of96px
, a display offlex
and ajustify-content
ofspace-around
. - Add a new selector for
#ports > .port
. Specify a width of64px
, a height of32px
and set the background image to theport.png
image file. - Add a new method to the
Controller
prototype calledrenderPorts
. It should have a parameter ofports
which will receive an array as an argument. - Inside
renderPorts
, usedocument.querySelector
to find theports
div and assign it to a variable namedportsElement
. SetportElement
's width to0px
. - You should then iterate over the array passed to the
ports
parameter usingforEach
and for each one should render a newdiv
to the DOM with the classport
- Each new port element should have a data attribute of
portIndex
set to the port's index in theports
array - Add 256px to the
#ports
div every time a new port element is appended to it - In the inline
script
block inindex.html
, call thecontroller.renderPorts
method, passing in yourItinerary
instance'sports
.