Skip to content

Commit df98b12

Browse files
committed
lesson-14
1 parent 97a7583 commit df98b12

File tree

6 files changed

+48
-45
lines changed

6 files changed

+48
-45
lines changed

public/app.js

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1-
"use strict";
2-
// classes
3-
var Invoice = /** @class */ (function () {
4-
// readonly client: string;
5-
// private details: string;
6-
// public amount: number;
7-
function Invoice(client, details, amount) {
8-
this.client = client;
9-
this.details = details;
10-
this.amount = amount;
11-
}
12-
Invoice.prototype.format = function () {
13-
return this.client + " owes \u00A3" + this.amount + " for " + this.details;
14-
};
15-
return Invoice;
16-
}());
17-
var invOne = new Invoice('mario', 'work on the mario website', 250);
18-
var invTwo = new Invoice('luigi', 'work on the luigi website', 300);
19-
var invoices = [];
1+
import { Invoice } from './classes/Invoice.js';
2+
const invOne = new Invoice('mario', 'work on the mario website', 250);
3+
const invTwo = new Invoice('luigi', 'work on the luigi website', 300);
4+
// invOne.client = 'yoshi';
5+
// invOne.amount = 50;
6+
let invoices = [];
207
invoices.push(invOne);
218
invoices.push(invTwo);
22-
invoices.forEach(function (inv) {
9+
invoices.forEach(inv => {
2310
console.log(inv.client, /*inv.details,*/ inv.amount, inv.format());
2411
});
25-
var form = document.querySelector('.new-item-form');
12+
const form = document.querySelector('.new-item-form');
2613
console.log(form.children);
2714
// inputs
28-
var type = document.querySelector('#type');
29-
var tofrom = document.querySelector('#tofrom');
30-
var details = document.querySelector('#details');
31-
var amount = document.querySelector('#amount');
32-
form.addEventListener('submit', function (e) {
15+
const type = document.querySelector('#type');
16+
const tofrom = document.querySelector('#tofrom');
17+
const details = document.querySelector('#details');
18+
const amount = document.querySelector('#amount');
19+
form.addEventListener('submit', (e) => {
3320
e.preventDefault();
3421
console.log(type.value, tofrom.value, details.value, amount.valueAsNumber);
3522
});

public/classes/Invoice.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export class Invoice {
2+
// readonly client: string;
3+
// private details: string;
4+
// public amount: number;
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+
}

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: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
// classes
2-
class Invoice {
3-
// readonly client: string;
4-
// private details: string;
5-
// public amount: number;
6-
7-
constructor(
8-
readonly client: string,
9-
private details: string,
10-
public amount: number,
11-
){}
12-
13-
format() {
14-
return `${this.client} owes £${this.amount} for ${this.details}`;
15-
}
16-
}
1+
import { Invoice } from './classes/Invoice.js';
172

183
const invOne = new Invoice('mario', 'work on the mario website', 250);
194
const invTwo = new Invoice('luigi', 'work on the luigi website', 300);
205

6+
// invOne.client = 'yoshi';
7+
// invOne.amount = 50;
8+
219
let invoices: Invoice[] = [];
2210
invoices.push(invOne)
2311
invoices.push(invTwo);

src/classes/Invoice.ts

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

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"compilerOptions": {
33
/* Basic Options */
44
// "incremental": true, /* Enable incremental compilation */
5-
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
6-
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
5+
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
6+
"module": "es2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
77
// "lib": [], /* Specify library files to be included in the compilation. */
88
// "allowJs": true, /* Allow javascript files to be compiled. */
99
// "checkJs": true, /* Report errors in .js files. */

0 commit comments

Comments
 (0)