Write a function that joins a name and a city with the word from.
Acceptance criteria
- 1.#out should show Ada from London.
JavaScript Tutorial · JavaScript Functions
These 10 tasks go with the JavaScript Function Parameters 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: “JavaScript function parameters are the names listed when a function is defined.” .
1.Use two parametersexercise · easy · 10 min
Write a function that joins a name and a city with the word from.
Passes when: #out should show Ada from London.
2.Order mattersexercise · easy · 10 min · practice plan
Call a divide function so it works out 20 divided by 4.
Passes when: #out should show 5.
3.Handle a missing argumentexercise · easy · 10 min · practice plan
Show the word missing when the second argument is left out.
Passes when: #out should show missing.
4.Parameters are localexercise · easy · 10 min · practice plan
Show that changing a parameter does not change the outside variable.
Passes when: #out should show 10.
5.Objects are sharedexercise · medium · 10 min · practice plan
Change a property inside a function and show the object was really changed.
Passes when: #out should show Grace.
6.Fix the swapped argumentsbug fix · easy · 8 min
The two values are passed in the wrong order.
Passes when: #out should show Ada from London.
7.Fix the reversed divisionbug fix · easy · 8 min · practice plan
The parameters are divided the wrong way round.
Passes when: #out should show 5.
8.Fix the wrong emptiness checkbug fix · easy · 8 min · practice plan
Comparing with null does not catch a missing argument.
Passes when: #out should show missing.
9.Fix the parameter name typobug fix · easy · 8 min · practice plan
The body uses a name that does not exist.
Passes when: #out should show 50.
10.Fix the object that was replacedbug fix · easy · 8 min · practice plan
Replacing the parameter does not change the original object.
Passes when: #out should show Grace.
Between them these tasks cover Parameters and arguments, Argument order and Pass by reference.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.