-
Notifications
You must be signed in to change notification settings - Fork 0
/
Typescript Test.tsx
55 lines (37 loc) · 938 Bytes
/
Typescript Test.tsx
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//this function flips the case of the word inputted
function flip_case(word: string)
{
let new_word = "";
for(var letter of word)
{
if(letter.toUpperCase() == letter)
{
new_word += letter.toLowerCase();
}
else
{
new_word += letter.toUpperCase();
}
}
return new_word;
}
let input = "fLIP cASE";
input = flip_case(input);
console.log(input + " worked");
//this function edits the variable depending on the type of the object
function union_type(two_type: string|number)
{
if (typeof two_type === "string")
{
two_type = two_type.toLowerCase();
}
else
{
two_type += 5;
}
return two_type;
}
let input1 = "HELLO";
let input2 = 10;
console.log("Input1 says: " + union_type(input1));
console.log("Input2 says: " + union_type(input2));