Ad
Code
Diff
  • describeAge=a=>`You're a(n) ${["kid","teenager","adult","elderly"][(a>=13)+(a>=18)+(a>=65)]}`
    • describeAge=a=>`You're a(n) ${["kid","teenager","adult","elderly"][(a>=13)+(a>=18)+(a>=65)]}`;
    • describeAge=a=>`You're a(n) ${["kid","teenager","adult","elderly"][(a>=13)+(a>=18)+(a>=65)]}`

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

If the age is 12 or lower, it return "You're a(n) kid"

If the age is anything between 13 and 17 (inclusive), it return "You're a(n) teenager"

If the age is anything between 18 and 64 (inclusive), it return "You're a(n) adult"

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:

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!
Don't you think the whole "You're a(n) <insert_something_here>" is very repetitive? ;) Perhaps we can shorten it?
Write everything in one line, \n and other whitespaces counts.
Whatever you do, do not change what the function does. Good luck :)

// describeAge(9) // => "You're a(n) kid"
// describeAge(10) // => "You're a(n) kid"
// describeAge(11) // => "You're a(n) kid"
// describeAge(12) // => "You're a(n) kid"
// describeAge(13) // => "You're a(n) teenager"
// describeAge(14) // => "You're a(n) teenager"
// describeAge(15) // => "You're a(n) teenager"
// describeAge(16) // => "You're a(n) teenager"
// describeAge(17) // => "You're a(n) teenager"
// describeAge(18) // => "You're a(n) adult"
// describeAge(19) // => "You're a(n) adult"
// describeAge(63) // => "You're a(n) adult"
// describeAge(64) // => "You're a(n) adult"
// describeAge(65) // => "You're a(n) elderly"
// describeAge(66) // => "You're a(n) elderly"
// describeAge(100) // => "You're a(n) elderly"

describeAge = a => {
  //write your code here
  }

Write function RemoveExclamationMarks which removes all exclamation marks from a given string.

function removeExclamationMarks(s) {
  }

Create a function that takes a string and returns the number of vowels in that string.

function vowels(str) {
  //code here
  }