Recap - Solar System
Part of the Logic & Flow section of Coddy's JavaScript journey — lesson 27 of 65.
Challenge
EasyCreate a function named analyzeSolarSystem that takes one argument, a JSON string solarSystemData. The JSON string contains information about planets in our solar system. Each planet has the following properties:
name(string)type(string: "rocky" or "gas")numberOfMoons(number)discoveredIn(number, year)surfaceTemperature(object with min and max in Celsius)hasRings(boolean)
Your task:
- Parse the JSON string into an object.
- For each planet:
- Add a property
classificationbased on these rules:- If it's a rocky planet and
surfaceTemperature.max< 50°C:Potentially Habitable - If it's a rocky planet and
surfaceTemperature.max>= 50°C:Extreme Environment - If it's a gas planet and
numberOfMoons> 10:Complex System - If it's a gas planet and
numberOfMoons<= 10:Simple Gas Giant
- If it's a rocky planet and
- Add a property
ageOfDiscoverythat calculates how many years ago the planet was discovered (from the year2010) - If the planet has rings and more than 5 moons, add a property
specialFeaturewith valueRing System with Rich Moon Population
- Add a property
- Return the modified object as a JSON string.
Example input:
{
"planets": [
{
"name": "Mars",
"type": "rocky",
"numberOfMoons": 2,
"discoveredIn": -3000,
"surfaceTemperature": {
"min": -140,
"max": 20
},
"hasRings": false
},
{
"name": "Saturn",
"type": "gas",
"numberOfMoons": 82,
"discoveredIn": -3000,
"surfaceTemperature": {
"min": -178,
"max": -138
},
"hasRings": true
}
]
}Try it yourself
function analyzeSolarSystem(solarSystemData) {
// Write code here
}
// Don't write anything outside the functionAll lessons in Logic & Flow
1Strings In Depth
String FundamentalsIterate Over StringsTemplate LiteralsString MethodsRecap - String Weaver4JSON Part 2
Iterate Over JSONNested JSONJSON Optional ChainingShallow And Deep CopyRecap - Bicycle ShopRecap - Solar System10Manage Festival System
Project OverviewAdd Movies & Venues2Multi-dimensional Arrays
2D Arrays BasicsAccessing 2D Array ElementsNested Loops with 2D ArraysRecap - 2D ArraysMatrix Addition & SubstractionJagged Arrays3D Arrays And BeyondCommon 2D Array PatternsRecap - All About Arrays5Sets Part 1
What Is A Set?Iterating Over SetsAdding An ElementRemoving An ElementChecking If An Element ExistsSize And Is EmptyCopy And ClearRecap - Basic Of Sets8Arrays Interesting Topics
Array DestructuringSpread Syntax in ArraysSparse ArraysRecap - Arrays Workshop3JSON Part 1
What is a JSON?Check If Key ExistsObject MethodsThe Spread Operator Part 1The Spread Operator Part 2Remove KeysRecap - JSON Manipulate Keys