typestar

RGB to hex in JavaScript

Converts between the two color notations CSS accepts.

function rgbToHex(r, g, b) {
  const toHex = (n) => n.toString(16).padStart(2, "0");
  return "#" + toHex(r) + toHex(g) + toHex(b);
}

Keywords and builtins used here

The run, in numbers

Lines
4
Characters to type
129
Tokens
50
Three-star pace
85 tpm

At the three-star pace of 85 tokens a minute, this run takes about 35 seconds.

Type this snippet

Step 5 of 5 in Text, step 10 of 43 in Language basics.

← Previous Next →