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; }
Code language: JavaScript (javascript)

How to use the Hashtag Generator

const hashtag = generateHashtag("My New Hashtag !") console.log(hashtag); // #MyNewHashtag!
Code language: JavaScript (javascript)

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments