KatInterview

Name the CSS Function for Red-Green-Blue With Optional Alpha

StringsAuto-graded · 13 test cases
EasyAuto-gradedStringscssfundamentalstrivia

Last updated

Recall which CSS color function takes red, green and blue channels plus an optional opacity value, and return its canonical name as a string.

A stylesheet author wants to describe a color by giving its red, green, and blue channel amounts directly. They also want the option to attach a transparency (alpha) value, but they do not want to be forced to supply one.

Write a function that returns the name of the CSS color function that fits this description under the current CSS Color Module Level 4 specification.

Task

The function takes no arguments. It must return the canonical name of the CSS color function that:

  • takes red, green, and blue channels as its own named components, and
  • accepts an alpha (opacity) component that may be left out.

Output format

Return a plain Python str that matches exactly:

  • the function name in lowercase,
  • followed immediately by an empty pair of parentheses,
  • with no spaces, no arguments, and no other characters.

The comparison is an exact string match.

Notes

  • Some other color functions also permit an optional alpha, but only one of them is defined in terms of red, green, and blue channels.
  • A legacy alias exists for the older form of this function, in which transparency was a required fourth value. Your answer should be the modern function, not the alias.

Constraints

  • The function takes no parameters.
  • The return type is str.
  • The returned string must be lowercase and include the trailing ().
  • Do not return example calls such as a name with channel values filled in.

Examples

Example 1

Input: name_rgb_color_function()

Output: 'rgb()'

Hints

Hint 1

Think about which CSS color functions are built from red, green and blue channels rather than hue, lightness, or a named color space.

Hint 2

In older CSS there were two functions: one for opaque colors and one that required alpha. Modern CSS merged them so alpha is optional on a single function.

Hint 3

Format matters: return the lowercase name followed by empty parentheses, with nothing inside them and no extra whitespace.