Back to Freecodecamp

Basic Functions Exercise C

curriculum/challenges/english/blocks/top-basic-function-projects/661e151f068359c3ccf2f4d7.md

latest673 B
Original Source

--description--

Write a function, named capitalize, that takes a string as an parameter and returns a new string with the first letter capitalized.

--hints--

You should have a function named capitalize.

js
assert.isFunction(capitalize);

Your function should take in a string as a parameter.

js
assert.match(capitalize.toString(), /\s*capitalize\(\s*\w+\s*\)/);

Your function should return a new string with the first letter capitalized.

js
assert.strictEqual(capitalize('sem'), 'Sem');

--seed--

--seed-contents--

js

--solutions--

js
function capitalize(str) {
  return str[0].toUpperCase() + str.slice(1);
}