Introduction
In this lab, we will explore the fundamental concepts of JavaScript programming. The purpose of this lab is to provide hands-on experience to learners who are new to JavaScript programming. Through a series of exercises and challenges, learners will gain a solid understanding of the basics of the language, including variables, data types, operators, and control flow. The lab is designed to be interactive and engaging, with plenty of opportunities to practice coding and receive feedback along the way.
How to Capitalize Every Word in JavaScript
To capitalize every word in a string using JavaScript, you can use the String.prototype.replace() method to match the first character of each word, and then use the String.prototype.toUpperCase() method to capitalize it.
Here's an example code snippet you can use:
const capitalizeEveryWord = (str) =>
str.replace(/\b[a-z]/g, (char) => char.toUpperCase());
To use this function, pass in the string you want to capitalize as an argument, like this:
capitalizeEveryWord("hello world!"); // 'Hello World!'
This will return the capitalized string 'Hello World!'.
Summary
Congratulations! You have completed the Capitalize Every Word lab. You can practice more labs in LabEx to improve your skills.