Join the property names of the object with a dash.
Acceptance criteria
- 1.#out should show name-age-city.
JavaScript Tutorial · JavaScript Loops
These 10 tasks go with the JavaScript for in Loop chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “The JavaScript for in loop is used to loop through the properties of an object.” .
1.List the property namesexercise · easy · 10 min
Join the property names of the object with a dash.
Passes when: #out should show name-age-city.
2.Count the propertiesexercise · easy · 10 min · practice plan
Count how many properties the object has.
Passes when: #out should show 4.
3.Add up the valuesexercise · easy · 10 min · practice plan
Add every value in the object together and show the total.
Passes when: #out should show 90.
4.Find a property by its valueexercise · easy · 10 min · practice plan
Find which subject scored 25 and show its name.
Passes when: #out should show science.
5.Join names and valuesexercise · medium · 10 min · practice plan
Build a string of every property as name=value, separated by commas.
Passes when: #out should show a=1,b=2.
6.Fix the value used as a namebug fix · easy · 8 min
The loop variable holds the property name, not the value.
Passes when: #out should show name-age-city.
7.Fix the missing bracketsbug fix · easy · 8 min · practice plan
Adding the property name instead of the value gives the wrong total.
Passes when: #out should show 90.
8.Fix the dot used with a variablebug fix · easy · 8 min · practice plan
scores.key looks for a property actually named "key".
Passes when: #out should show 90.
9.Fix the counter that counts lettersbug fix · easy · 8 min · practice plan
This counts the characters of each name instead of the properties.
Passes when: #out should show 4.
10.Fix the missing breakbug fix · easy · 8 min · practice plan
Without break the loop keeps going and reports the last match.
Passes when: #out should show the first match, maths.
Between them these tasks cover for in, Object properties and Reading values by key.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.