Beginner
Read properties safely
Write getCity(user): it returns user.address.city, or "Unknown" when the user, the address or the city is missing (null or undefined). An empty string "" is a real value: return it as it is.
Write hasKey(obj, key): it returns true only if obj has key as its own property (inherited ones like toString don't count), even if the value is undefined.
What Check tests
getCityreturns the city when it existsgetCityreturns"Unknown"for a missing address, user or city- An empty city
""is kept hasKeyfinds own keys, even holdingundefinedhasKeyignores inherited keys liketoString
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.