Skip to content

Commit cb434ed

Browse files
committed
Add week-2 in-lecture code examples
1 parent 7af2ccb commit cb434ed

File tree

7 files changed

+126
-19
lines changed

7 files changed

+126
-19
lines changed

week-2/data.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Women Tech Makers Berlin","location":"Eurostaff","attendees":[{"name":"Armagan","age":34},{"name":"Mert","age":33}]}

week-2/database.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const fs = require('fs')
2+
module.exports = {
3+
save(data) {
4+
// console.log(data)
5+
fs.writeFileSync('data.json', JSON.stringify(data))
6+
},
7+
load() {
8+
return JSON.parse(fs.readFileSync('data.json'))
9+
}
10+
}

week-2/index.js

+22-19
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
class Meetup {
2-
constructor(name, location) {
3-
this.name = name
4-
this.location = location
5-
this.attendees = []
6-
}
1+
const Person = require('./person')
2+
const Meetup = require('./meetup')
3+
const Database = require('./database')
74

8-
report() {
9-
console.log(this.name, 'meetup is held at', this.location, 'and number of attendees are', this.attendees.length)
10-
}
11-
}
5+
console.log('Hello World!')
126

13-
class Person {
14-
constructor(name, age) {
15-
this.name = name
16-
this.age = age
17-
}
7+
const add = (num1, num2) => num1 + num2
8+
const addResult = add(4, 7)
9+
const multiply = (num1, num2) => num1 * num2
10+
// console.log(addResult)
11+
const multiplyResult = multiply(addResult, 6)
12+
// console.log(multiplyResult)
1813

19-
attend(meetup) {
20-
meetup.attendees.push(this)
21-
}
22-
}
14+
const mert = new Person('Mert', 33)
15+
const armagan = new Person('Armagan', 34)
16+
// console.log(mert, armagan)
17+
18+
const wtmb = new Meetup('Women Tech Makers Berlin', 'Eurostaff')
19+
armagan.attend(wtmb)
20+
mert.attend(wtmb)
21+
wtmb.report()
22+
23+
Database.save(wtmb)
24+
const loadedFile = Database.load()
25+
console.log(loadedFile.attendees[0].name)

week-2/meetup.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const Chalk = require('chalk')
2+
module.exports = class Meetup {
3+
constructor(name, location) {
4+
this.name = name
5+
this.location = location
6+
this.attendees = []
7+
}
8+
9+
report() {
10+
console.log(Chalk.blue.bgRed.bold(this.name), 'meetup is held at', Chalk.green(this.location), 'and number of attendees are', this.attendees.length)
11+
}
12+
}

week-2/package-lock.json

+57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

week-2/package.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "week-2",
3+
"version": "1.0.0",
4+
"description": "WTM Berlin JS Crash Course 2018 Lecture 2 - Node.js",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "Mert Cetin <[email protected]>",
10+
"license": "MIT",
11+
"dependencies": {
12+
"chalk": "^2.4.1"
13+
}
14+
}

week-2/person.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = class Person {
2+
constructor(name, age) {
3+
this.name = name
4+
this.age = age
5+
}
6+
7+
attend(meetup) {
8+
meetup.attendees.push(this)
9+
}
10+
}

0 commit comments

Comments
 (0)