09.05 · Ternary & conditional challenges / Practice · 6 min
Check the age boundaries
The ticket says 65, but the program picks the wrong category. Check the boundary.
Activity 5 of 6 in Ternary & conditional challenges
JavaScript Basics / 09.05
Check the age boundaries
Not started
Follow the original age-verification challenge and include both endpoints of its adult category.

Include age boundaries in a branch chain
Work through 4 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)4 steps · Saved work · Instant feedback
YOUR TURN
Check the age boundaries
Complete the if/else-if/else chain. Below 18 prints You are underage.; 18 through 65 inclusive prints You are an adult.; above 65 prints You are a senior citizen. Keep age = 65 for the browser check. This is a fictional categorization exercise, not a legal age rule.
You are an adult.
Keep the starting inputs. Print these lines in this order, without extra output.
Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.
Ready to checkRun the checks to see your results here.
Your check results
Work in VS Code instead
Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.
const age = 65;
if (age < 18) {
console.log("You are underage.");
} else if (age < 65) {
console.log("You are an adult.");
} else {
console.log("You are a senior citizen.");
}Need a nudge?
Follow the chain
The second condition is reached only when the age is not below 18. Focus on its upper boundary.
Include the endpoint
The task includes 65 in the adult range. Compare < with <=.
Reveal a possible solution
const age = 65;
if (age < 18) {
console.log("You are underage.");
} else if (age <= 65) {
console.log("You are an adult.");
} else {
console.log("You are a senior citizen.");
}Test 17, 18, 64, 65 and 66. The starting check is a boundary regression check, not full input validation. The original prompt-based version expects a valid nonnegative whole-number age; validation can be a later extension.
Open the code-along notes
From prompt input to a repeatable check
Your original challenge asks for an age using prompt() and parseInt(). Here a fixed age makes the browser check repeatable. After it works, try other valid whole-number ages.
In a local browser version you can replace the first line with const age = Number(prompt("Enter your age:"));. That version also needs cancellation, blank-input and invalid-number handling; the boundary exercise assumes a valid input. Use an if/else-if chain rather than nesting ternaries.
// Try these separately by changing the age input.
// 17: underage
// 18 and 65: adult
// 66: senior citizenReady to try it?
Practice in your browser and see your results.
Progress details
Have a question?
Ask the Code Zone community.
Ask a question in The Code Zone (opens in a new tab)Continue learning

7 days freeTry The Code Zone
THE CODE ZONE COMMUNITY
Your next step is easier together.
Try the community free for 7 days.
No charge during your trial. Choose your plan on Skool.
- Ask questions and get support in the community
- Watch every course video walkthrough
- Find a study buddy in the 24/7 study room
Make the most of your trial with Premium.
Choose Premium on Skool to try Thursday live help sessions. Bring your questions, work through code, and get unstuck together.
Scheduled Thursdays in Eastern Time. Check the Skool calendar for your local date and time.
Have a website account? Sign in