How to Create a Hashtag Generator in Javascript


If you want to create a hashtag generator in Javascript, then you can do the following:

function generateHashtag(string) {
  if (string.trim() === '') return false;

  const stringWithCamelCase = string
    .split(' ')
    .map(word => word.charAt(0).toUpperCase() + word.slice(1))
    .join('');

  const stringWithHashtag = `#${stringWithCamelCase.trim()}`;

  return stringWithHashtag.length > 140 ? false : stringWithHashtag;
}

How to use the Hashtag Generator

const hashtag = generateHashtag("My New Hashtag !")

console.log(hashtag);
// #MyNewHashtag!