-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment03.ts
34 lines (27 loc) · 1.4 KB
/
assignment03.ts
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
29
30
31
32
33
const user_name:String="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:Boolean=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:String[]=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:String=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:String=user_name.replace(user_name[0],user_name[0].toUpperCase())
console.log(`The Persons name in Title case is: ${InTitleCase}`)
Start=false
}
}