-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayground.ts
60 lines (51 loc) · 1.2 KB
/
playground.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
let isDone: boolean = false;
let age: number = 25;
let list: number[] = [1, 2, 3];
let tuple: [string, number] = ["hello", 10];
// Defining an interface for a person
interface Person {
name: string;
age?: number; // Optional property
sayHello(): string; // Method
}
const user: Person = {
name: "Rhababer Rhababer",
age: 30,
sayHello: function (): string {
return `Hello, my name is ${this.name}`;
},
};
function add(x: number, y: number): number {
return x + y;
}
const subtract = (x: number, y: number): number => {
return x - y;
}
// Look I don’t know any Typescript, okay?
const answers: string[] = [
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes, definitely",
"You may rely on it",
"As I see it, yes",
"Most likely",
"Outlook good",
"Yes",
"Signs point to yes",
"Reply hazy, try again",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Concentrate and ask again",
"Don't count on it",
"My reply is no",
"My sources say no",
"Outlook not so good",
"Very doubtful"
];
// Shake the damn thing
function shake(): string {
const randomIndex = Math.floor(Math.random() * answers.length);
return answers[randomIndex];
}