Report adult when the age is 18 or more.
Acceptance criteria
- 1.#out should show adult.
JavaScript Tutorial · JavaScript Conditions
These 10 tasks go with the JavaScript Ternary Operator 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 ternary operator is a short way to choose between two values.” .
1.Choose between two valuesexercise · easy · 10 min
Report adult when the age is 18 or more.
Passes when: #out should show adult.
2.Pick the singular or pluralexercise · easy · 10 min · practice plan
Report the right wording for a count of one.
Passes when: #out should show 1 item.
3.Return from a functionexercise · easy · 10 min · practice plan
Return a lower fee for members.
Passes when: #out should show 5 and 10.
4.Chain two ternariesexercise · easy · 10 min · practice plan
Report a grade of B for a score of 75.
Passes when: #out should show B.
5.Use it inside a stringexercise · medium · 10 min · practice plan
Build a sentence that changes with the value.
Passes when: #out should show Ada is online.
6.Fix the branches the wrong way roundbug fix · easy · 8 min
The true and false values have been swapped.
Passes when: #out should show adult.
7.Fix the singular and plural swappedbug fix · easy · 8 min · practice plan
A count of two should read items, not item.
Passes when: #out should show 2 items.
8.Fix the missing bracketsbug fix · easy · 8 min · practice plan
Without brackets the join happens before the choice.
Passes when: #out should show Ada is online.
9.Fix the comparison that is always truebug fix · easy · 8 min · practice plan
A single equals assigns instead of comparing.
Passes when: #out should show not a member.
10.Fix the grade boundariesbug fix · easy · 8 min · practice plan
A score of 75 should be a B, not a C.
Passes when: #out should show grade B.
Between them these tasks cover Ternary operator, Expressions and Conditional values.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.