Declare a function named square and show square of 9.
Acceptance criteria
- 1.#out should show 81.
JavaScript Tutorial · JavaScript Functions
These 10 tasks go with the JavaScript Function Declarations 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: “A JavaScript function declaration defines a named function using the function keyword.” .
1.Declare a functionexercise · easy · 10 min
Declare a function named square and show square of 9.
Passes when: #out should show 81.
2.Call before the declarationexercise · easy · 10 min · practice plan
Call a declared function on a line above it and show the answer for 7.
Passes when: #out should show 49.
3.Two parametersexercise · easy · 10 min · practice plan
Declare a function that joins a first and last name with a space.
Passes when: #out should show Ada Lovelace.
4.No parametersexercise · easy · 10 min · practice plan
Declare a function that takes nothing and returns the word Ready.
Passes when: #out should show Ready.
5.Branch inside a functionexercise · medium · 10 min · practice plan
Declare a function returning Adult for 18 or over, Minor otherwise. Show the answer for 15.
Passes when: #out should show Minor.
6.Fix the misspelled keywordbug fix · easy · 8 min
The keyword is function, spelled in full.
Passes when: #out should show 81.
7.Fix the duplicate declarationbug fix · easy · 8 min · practice plan
The later declaration replaces the first one.
Passes when: #out should show Second wins.
8.Fix the swapped parametersbug fix · easy · 8 min · practice plan
The names come back in the wrong order.
Passes when: #out should show Ada Lovelace.
9.Fix the missing spacebug fix · easy · 8 min · practice plan
The two names run together with no gap.
Passes when: #out should show Ada Lovelace with a space.
10.Fix the inverted conditionbug fix · easy · 8 min · practice plan
The age test is the wrong way round.
Passes when: #out should show Minor for age 15.
Between them these tasks cover Function declarations, Hoisting and Naming.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.