Skip to content

Solution/first tweet and water day#18

Open
sh3rqxs wants to merge 2 commits intocodedex-io:mainfrom
sh3rqxs:solution/first-tweet-and-water-day
Open

Solution/first tweet and water day#18
sh3rqxs wants to merge 2 commits intocodedex-io:mainfrom
sh3rqxs:solution/first-tweet-and-water-day

Conversation

@sh3rqxs
Copy link
Copy Markdown
Contributor

@sh3rqxs sh3rqxs commented Mar 23, 2026

Hii again, here are my solutions for day 20 and day 21.

What I did:

  1. First Tweet 🐦

    • Defined 3 variables:

      • charsLeft β€” the character limit, initialized to 140.
      • count β€” a running total of characters typed, initialized to 0.
      • string β€” an array of the tweet's words, split on spaces.
    • Iterated over each word in string using a for...of loop.

    • Applied different character counts based on the type of each word:

      • Usernames (starting with @) β†’ counted as 20 chars.
      • URLs (starting with http:// or https://) β†’ counted as 23 chars.
      • Emojis β†’ counted as 2 chars.
      • Everything else (regular words, punctuation, etc.) β†’ counted normally.
    • Added 1 to count per word to account for the space following it.

    • Returned the remaining characters as charsLeft - count.

  2. Water Day πŸ’§

    • Defined 4 variables:

      • currentVolume β€” the initial volume of water.
      • lossRate β€” the leak.
      • iterations β€” the number of hours.
      • waterRemaining β€” the final volume of water.
    • Created a loop using a classic for loop.

    • Calculated the fixed percentage a pipe loses each hour with β†’ new volume = current volume * (1 - leak/100).

    • Added a condition to return the volume of water remaining after all hours have passed:

      • If the currentVolume >= threshold, returns waterRemaining = Number(currentVolume.toFixed(2)).
      • Else, returns -1.

Let me know if there's anything to fix!
shercodes πŸ’–

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant