8 kyu

Be Concise I - The Ternary Operator

5,902 of 8,109donaldsebleung

Description:

Be Concise I - The Ternary Operator

You are given a function describeAge / describe_age that takes a parameter age (which will always be a positive integer) and does the following:

  1. If the age is 12 or lower, it return "You're a(n) kid"
  2. If the age is anything between 13 and 17 (inclusive), it return "You're a(n) teenager"
  3. If the age is anything between 18 and 64 (inclusive), it return "You're a(n) adult"
  4. If the age is 65 or above, it return "You're a(n) elderly"

Your task is to shorten the code as much as possible. Note that submitting the given code will not work because there is a character limit of 137.

I'll give you a few hints:

  1. The title itself is a hint - if you're not sure what to do, always research any terminology in this description that you have not heard of!
  2. Don't you think the whole "You're a(n) <insert_something_here>" is very repetitive? ;) Perhaps we can shorten it?
  3. Write everything in one line, \n and other whitespaces counts.

Whatever you do, do not change what the function does. Good luck :)

Fundamentals
Refactoring

Stats:

CreatedMar 24, 2016
PublishedMar 24, 2016
Warriors Trained12817
Total Skips181
Total Code Submissions69222
Total Times Completed8109
JavaScript Completions5902
CoffeeScript Completions17
Ruby Completions228
Java Completions1044
Python Completions1126
Total Stars122
% of votes with a positive feedback rating84% of 1580
Total "Very Satisfied" Votes1217
Total "Somewhat Satisfied" Votes229
Total "Not Satisfied" Votes134
Ad
Contributors
  • donaldsebleung Avatar
  • Javatlacati Avatar
  • myjinxin2015 Avatar
  • kazk Avatar
  • B1ts Avatar
  • albertogcmr Avatar
  • pawptart Avatar
  • user8436785 Avatar
  • ZywOo Avatar
  • Kacarott Avatar
  • PetitLu117 Avatar
Ad