Homework
The Solar System
Create an HTML page and a JavaScript file and link the two.
The following object, solarSystem
, is a common data structure: an array of objects. You will see this particular data structure more and more as you venture into JSON and servers. This one is an array of objects which also contains arrays.
Note that the objects do not have names. They are just anonymous objects listed in an array.
Copy and paste this object into your .js
file:
Write JavaScript that does the following:
Print the array of Jupiter's moons to the console (no for loop, just print the entire array).
Print the name of Neptune's moon "Nereid" to the console.
Add a new moon called "Endor" to Venus' moons array.
Add a Pluto object to the solarSystem array using .push. The object should contain Pluto's name, ringSystem boolean, and moons array (which includes "Charon").
Add a new key value pair to the the Earth object: the key should be 'diameter', and the value should be Earth's diameter in miles represented as a string.
Change Mercury's ringSystem boolean to true.
Change Uranus' moon "Umbriel" to "Oberon"
Iterate through the solarSystem array and print only the objects that have a ringSystem (where ringSystem: true), and ignore the others. You want to make a loop that goes over each item in the array, and include an if statement.
Example output:
Friends
Create a separate HTML page and a JavaScript file and link the two. Copy the code block below into your .js
file and answer the numbered questions.
Last updated
Was this helpful?