javascript-learning-labs

String Manipulation Labs

πŸ“ Description

This folder contains JavaScript exercises focused on working with strings β€” including slicing, masking, formatting, and rebuilding text. Each lab practices real-world concepts such as input handling, UI-friendly formatting, and safe data display.

More string-focused labs will be added here as I continue learning.


πŸ“§ Mask Email Function

This exercise practices JavaScript string manipulation by hiding part of an email address for privacy. The function returns a masked version where only the first and last character of the username are visible β€” the rest are replaced with *. The domain remains unchanged.

πŸ“Œ Example Behavior (Mask Email)

jsmith@example.com β†’ j****h@example.com

πŸ› οΈ Concepts Practiced (Mask Email)

πŸ’‘ Reflection (Mask Email)

This lab helped me practice breaking a problem into smaller steps, working with string indexes, and reconstructing text from multiple parts. It also introduced real-world privacy considerations β€” such as masking account details before displaying them to users.


πŸ” Reverse String Function

This exercise builds a function that reverses a string character-by-character without using JavaScript’s built-in .reverse() method. The goal is to practice manual string traversal and reconstruction using core language features.

πŸ“Œ Example Behavior (Reverse String)

reverseString("hello") β†’ "olleh"
reverseString("JavaScript") β†’ "tpircSavaJ"

πŸ› οΈ Concepts Practiced (Reverse String)

πŸ’‘ Reflection (Reverse String)

This lab reinforced how strings can be traversed like arrays and how new strings must be constructed explicitly due to string immutability in JavaScript. It also helped solidify loop control and index-based access β€” foundational skills that apply across many algorithms and UI-related string transformations.


βœ‚οΈ Truncate String Function

This exercise truncates text when it exceeds a specified length and appends an ellipsis (...). If the string is already short enough, it returns the original value unchanged.

πŸ“Œ Example Behavior (Truncate String)

truncateString("Hello World",5) β†’ "Hello..."

πŸ› οΈ Concepts Practiced (Truncate String)

πŸ’‘ Reflection (Truncate String)

This lab helped reinforce how conditional logic and string length checks work together. It also connects directly to real UI patterns β€” like shortening long titles or preview text without altering the underlying data.


βœ… Confirm String Ending

This exercise checks whether a given string ends with a specified target string. The solution was implemented without using .endsWith(), relying instead on string slicing and length comparison.

πŸ“Œ Example Behavior (Confirm String Ending)

confirmEnding("Bastian", "n") β†’ true
confirmEnding("Open Sesame", "sage") β†’ false

πŸ› οΈ Concepts Practiced (Confirm String Ending)

πŸ’‘ Reflection (Confirm String Ending)

This lab helped solidify my understanding of how string indexing works and how built-in methods can be recreated using fundamental operations. It also reinforced the importance of reading problem constraints carefully and choosing simple, direct solutions.


πŸ”  Title Case Converter

This exercise converts an input string into title case, meaning the first letter of every word is capitalized while the remaining letters are lowercase.

The solution normalizes the string, breaks it into individual words, transforms each word, and then reconstructs the final result.

πŸ“Œ Example Behavior (Title Case Converter)

titleCase("a little teapot") β†’ "A Little Teapot"
titleCase("sHoRt AnD sToUt") β†’ "Short And Stout"
titleCase("HERE IS MY HANDLE") β†’ "Here Is My Handle"

πŸ› οΈ Concepts Practiced (Title Case Converter)

πŸ’‘ Reflection (Title Case Converter)

This lab introduced a multi-step transformation workflow, moving beyond single-method string operations. It reinforced how strings and arrays can work together to process text data, a pattern that appears frequently in real-world applications such as formatting user input, cleaning data, and preparing for text display. It also emphasized the importance of thinking about edge cases like extra spaces or inconsistent capitalization.


πŸ” Random Password Generator

This mini project generates a random password of a specified length using a predefined set of uppercase letters, lowercase letters, numbers, and symbols.

πŸ“Œ Example Behavior (Password Generator)

generatePassword(8) β†’ "aZ3$kL9!"
generatePassword(15) β†’ "Qf2@Lm9!xZ1#pRt"

πŸ› οΈ Concepts Practiced (Password Generator)

πŸ’‘ Reflection (Password Generator)

This lab demonstrates how randomness can be used to generate dynamic output based on user input. It also highlights the difference between simple pseudo-random generation and more secure random generation methods used in real-world applications.


🧾 HTML Entity Converter

This exercise replaces reserved HTML characters in a string with their corresponding HTML entity representations. The function scans the input string character-by-character and substitutes only the characters that require escaping.

πŸ“Œ Example Behavior (HTML Entity Converter)

convertHTML("Dolce & Gabbana") β†’ "Dolce & Gabbana"
convertHTML("Hamburgers < Pizza < Tacos") β†’ "Hamburgers &lt; Pizza &lt; Tacos"
convertHTML('Stuff in "quotation marks"') β†’ "Stuff in &quot;quotation marks&quot;"

πŸ› οΈ Concepts Practiced (HTML Entity Converter)

πŸ’‘ Reflection (HTML Entity Converter)

This lab introduces the concept of HTML escaping, an important real-world string processing task. It reinforces how strings can be transformed safely by mapping specific characters to alternate representations. The exercise also highlights how controlled character replacement is used in web development to ensure text is displayed correctly without being interpreted as markup.


πŸ’‘ Topic Reflection

These labs focused on practical string manipulation patterns commonly used in real-world applications. Each exercise reinforced how small, focused string operations can be combined with conditional logic to safely format, validate, and display text.

Together, these labs helped build confidence working with user-facing data while maintaining clarity, readability, and intent in string-based logic.