Skip to content

Commit d4ba287

Browse files
author
ykyan-vtc
committed
lesson 15
1 parent c2355ad commit d4ba287

File tree

5 files changed

+76
-37
lines changed

5 files changed

+76
-37
lines changed

public/app.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
"use strict";
22
// const anchor = document.querySelector('a')!;
3-
// console.log(anchor.href);
4-
// Classes
5-
class Invoice {
6-
constructor(c, d, a) {
7-
this.client = c;
8-
this.details = d;
9-
this.amount = a;
10-
}
11-
format() {
12-
return `${this.client} owes $${this.amount} for ${this.details}.`;
3+
Object.defineProperty(exports, "__esModule", { value: true });
4+
const me = {
5+
name: 'Shuan',
6+
age: 30,
7+
speak(text) {
8+
console.log(text);
9+
},
10+
spend(amount) {
11+
console.log('I spend', amount);
12+
return amount;
1313
}
14-
}
15-
const invOne = new Invoice('mario', 'work on the mario website', 250);
16-
const invTwo = new Invoice('luigi', 'work on the luigi website', 300);
14+
};
15+
console.log(me);
16+
// Classes
17+
const Invoice_1 = require("./classes/Invoice");
18+
const invOne = new Invoice_1.Invoice('mario', 'work on the mario website', 250);
19+
const invTwo = new Invoice_1.Invoice('luigi', 'work on the luigi website', 300);
1720
let invoices = [];
1821
invoices.push(invOne);
1922
invoices.push(invTwo);
20-
console.log(invoices);
23+
invoices.forEach(inv => {
24+
console.log(inv.client, inv.amount, inv.format());
25+
});
2126
// const form = document.querySelector('form')!;
2227
const form = document.querySelector('.new-item-form');
2328
// console.log(form.children);

public/classes/Invoice.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.Invoice = void 0;
4+
class Invoice {
5+
constructor(client, details, amount) {
6+
this.client = client;
7+
this.details = details;
8+
this.amount = amount;
9+
}
10+
format() {
11+
return `${this.client} owes $${this.amount} for ${this.details}.`;
12+
}
13+
}
14+
exports.Invoice = Invoice;

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ <h1>Finance Logger</h1>
4343
<a href="https://www.thenetninja.co.uk">The Net Ninja</a>
4444
</footer>
4545

46-
<script src='app.js'></script>
46+
<script type="module" src='app.js'></script>
4747
</body>
4848
</html>

src/app.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,44 @@
22

33
// console.log(anchor.href);
44

5-
// Classes
6-
class Invoice {
7-
client: string;
8-
details: string;
9-
amount: number;
10-
11-
constructor(c: string, d: string, a: number){
12-
this.client = c;
13-
this.details = d;
14-
this.amount = a;
15-
}
16-
17-
format(){
18-
return `${this.client} owes $${this.amount} for ${this.details}.`;
5+
// interfaces
6+
interface IsPerson {
7+
name: string,
8+
age: number,
9+
speak(a: string): void;
10+
spend(a: number): number;
11+
}
1912

13+
const me: IsPerson = {
14+
name: 'Shuan',
15+
age: 30,
16+
speak(text: string): void{
17+
console.log(text);
18+
19+
},
20+
spend(amount: number):number{
21+
console.log('I spend', amount);
22+
return amount;
2023
}
2124
}
2225

23-
const invOne = new Invoice('mario', 'work on the mario website', 250);
24-
const invTwo = new Invoice('luigi', 'work on the luigi website', 300);
25-
26-
let invoices: Invoice[] = [];
27-
invoices.push(invOne);
28-
invoices.push(invTwo);
29-
30-
console.log(invoices);
26+
console.log(me);
3127

3228

3329

30+
// Classes
31+
import { Invoice } from "./classes/Invoice";
3432

33+
const invOne = new Invoice('mario', 'work on the mario website', 250);
34+
const invTwo = new Invoice('luigi', 'work on the luigi website', 300);
3535

36+
let invoices: Invoice[] = [];
3637

38+
invoices.push(invOne);
39+
invoices.push(invTwo);
40+
invoices.forEach(inv => {
41+
console.log(inv.client, inv.amount, inv.format());
42+
})
3743

3844

3945
// const form = document.querySelector('form')!;

src/classes/Invoice.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export class Invoice {
2+
3+
4+
constructor(
5+
readonly client: string,
6+
private details: string,
7+
public amount: number,
8+
){}
9+
10+
format(){
11+
return `${this.client} owes $${this.amount} for ${this.details}.`;
12+
13+
}
14+
}

0 commit comments

Comments
 (0)