Skip to content

Commit d034494

Browse files
committed
lesson 14
1 parent 245bd60 commit d034494

File tree

7 files changed

+107
-6
lines changed

7 files changed

+107
-6
lines changed

public/app.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//imports
2+
import { Invoice } from './classes/invoice.js';
3+
const form = document.querySelector(".new-item-form");
4+
//classes
5+
const invOne = new Invoice("Tonia", "web design work", 349, 25);
6+
const invTwo = new Invoice("Yosola", "iftar cooking", 200, 27);
7+
let invoices = [];
8+
invoices.push(invOne);
9+
invoices.push(invTwo);
10+
invoices.forEach(inv => {
11+
console.log(inv.client, inv.amount, inv.format());
12+
});
13+
//shorthand when using access modifiers
14+
class Money {
15+
constructor(client, details, amount) {
16+
this.client = client;
17+
this.details = details;
18+
this.amount = amount;
19+
}
20+
}
21+
//inputs
22+
const type = document.querySelector("#type");
23+
const tofrom = document.querySelector("#tofrom");
24+
const details = document.querySelector("#details");
25+
const amount = document.querySelector("#amount");
26+
form.addEventListener('submit', (e) => {
27+
e.preventDefault();
28+
console.log(type.value, tofrom.value, details.value, amount.valueAsNumber);
29+
});

public/classes/invoice.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export class Invoice {
2+
constructor(c, d, a, ag) {
3+
this.client = c;
4+
this.details = d;
5+
this.amount = a;
6+
this.age = ag;
7+
}
8+
format() {
9+
return `${this.client} is ${this.age}y/o and owes $${this.amount} for ${this.details}`;
10+
}
11+
}

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ <h1>Finance Logger</h1>
3838
</form>
3939
</footer>
4040

41-
<script src="index.js"></script>
41+
<script type="module" src="app.js"></script>
4242
</body>
4343
</html>

public/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ objectColc = {
1919
color: "green"
2020
};
2121
let objectOne;
22-
console.log("test watching");
2322
//function signatures
2423
let greet;
25-
greet = (number = 35, word = "hello there") => {
26-
console.log(number, word);
24+
greet = (num, word) => {
25+
console.log(num, word);
2726
};
27+
greet(24, "hello");
2828
//function signatures with type aliases
2929
let obj;
3030
obj = (person) => {
3131
console.log(`${person.name}, is ${person.age} years old and is a ${person.gender} `);
3232
};
33+
obj({ name: "tonia", age: 23, gender: true });

src/app.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//imports
2+
import {Invoice } from './classes/invoice.js';
3+
4+
const form = document.querySelector(".new-item-form")! as HTMLFormElement;
5+
6+
//classes
7+
8+
9+
const invOne = new Invoice("Tonia", "web design work", 349, 25);
10+
const invTwo = new Invoice("Yosola", "iftar cooking", 200, 27);
11+
12+
let invoices: Invoice[] =[];
13+
invoices.push(invOne)
14+
invoices.push(invTwo)
15+
invoices.forEach(inv=>{
16+
17+
console.log(inv.client, inv.amount, inv.format());
18+
})
19+
20+
//shorthand when using access modifiers
21+
class Money{
22+
constructor(
23+
readonly client:string,
24+
private details: string,
25+
public amount: number,
26+
){}
27+
}
28+
29+
30+
//inputs
31+
const type = document.querySelector("#type")! as HTMLSelectElement;
32+
const tofrom = document.querySelector("#tofrom")! as HTMLInputElement;
33+
const details = document.querySelector("#details")! as HTMLInputElement;
34+
const amount = document.querySelector("#amount")! as HTMLInputElement;
35+
36+
form.addEventListener('submit', (e)=>{
37+
e.preventDefault()
38+
console.log(type.value,
39+
tofrom.value,
40+
details.value,
41+
amount.valueAsNumber);
42+
})

src/classes/invoice.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export class Invoice{
2+
readonly client: string;
3+
private details: string;
4+
public amount: number;
5+
protected age: number;
6+
7+
constructor(c: string, d: string, a: number, ag: number){
8+
this.client = c;
9+
this.details = d;
10+
this.amount = a;
11+
this.age = ag;
12+
}
13+
14+
format(){
15+
return `${this.client} is ${this.age}y/o and owes $${this.amount} for ${this.details}`
16+
}
17+
}
18+

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1515

1616
/* Language and Environment */
17-
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
17+
"target": "es6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1818
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1919
// "jsx": "preserve", /* Specify what JSX code is generated. */
2020
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
@@ -28,7 +28,7 @@
2828
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2929

3030
/* Modules */
31-
"module": "commonjs", /* Specify what module code is generated. */
31+
"module": "es2015", /* Specify what module code is generated. */
3232
// "rootDir": "./", /* Specify the root folder within your source files. */
3333
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
3434
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */

0 commit comments

Comments
 (0)