Back to Freecodecamp

Challenge 90: Character Limit

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68f6587287ad1f4ad39b0c7c.md

latest1.3 KB
Original Source

--description--

In this challenge, you are given a string and need to determine if it fits in a social media post. Return the following strings based on the rules given:

  • "short post" if it fits within a 40-character limit.
  • "long post" if it's greater than 40 characters and fits within an 80-character limit.
  • "invalid post" if it's too long to fit within either limit.

--hints--

canPost("Hello world") should return "short post".

js
assert.equal(canPost("Hello world"), "short post");

canPost("This is a longer message but still under eighty characters.") should return "long post".

js
assert.equal(canPost("This is a longer message but still under eighty characters."), "long post");

canPost("This message is too long to fit into either of the character limits for a social media post.") should return "invalid post".

js
assert.equal(canPost("This message is too long to fit into either of the character limits for a social media post."), "invalid post");

--seed--

--seed-contents--

js
function canPost(message) {

  return message;
}

--solutions--

js
function canPost(message) {
  if (message.length <= 40) {
    return "short post"
  } else if (message.length <= 80) {
    return "long post"
  } else {
    return "invalid post"
  }
}