-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment03.js
28 lines (28 loc) · 1.42 KB
/
assignment03.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"use strict";
const user_name = "Muhammad Ali";
// Following code converts the string into Lower case
console.log(user_name.toUpperCase());
// Following code converts the string into Upper case
console.log(user_name.toLowerCase());
// Following code converts the string into Title case AS there is not funciton in the Javascript/Typescript to Convert into Title case therefore we will do it manually
let Start = true;
// Start the Loop
while (Start) {
// Following Condition checks weather the Name Data is single letter or Multi letter
if (user_name.split(' ').length > 1) {
// if MultiLetter THe String will coveted into Arrays then will be made in Titile case with Map function,
let InTitleCaseArr = user_name.split(' ').map((Name) => {
return Name.replace(Name[0], Name[0].toUpperCase());
});
// After Making The Title case one by one String will be joined and printed
let InTitleCase = InTitleCaseArr.join(' ');
console.log(`The Persons Name in Title case is: ${InTitleCase}`);
Start = false;
}
if (user_name.split(' ').length === 1) {
// if single letter there will be no Loop or Map Function be used, and it will simply make the data into Title format
let InTitleCase = user_name.replace(user_name[0], user_name[0].toUpperCase());
console.log(`The Persons name in Title case is: ${InTitleCase}`);
Start = false;
}
}