From d3b9878d54f2ea53921e2879f3d8c75eb925366b Mon Sep 17 00:00:00 2001 From: Supriya Puri Date: Mon, 13 Apr 2020 00:59:17 -0700 Subject: [PATCH 1/4] Working Week1 Assignment(Pre-submission) --- package.json | 3 ++- src/components/DivElement.js | 11 ++++++++ src/components/HTMLElement.js | 15 ++++++++++- src/rolodex/rolodexPrinter.js | 8 +++--- src/timer/Timer.js | 50 ++++++++++++++++++++++++++--------- src/timer/runTimer.js | 16 +++++++++-- test/DivElement.spec.js | 1 + 7 files changed, 83 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index e05edcb..b3198df 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "keywords": [], "author": "", "license": "ISC", + "type": "module", "devDependencies": { "@babel/cli": "^7.8.4", "@babel/core": "^7.9.0", @@ -20,6 +21,6 @@ "eslint": "^6.8.0", "eslint-config-airbnb-base": "^14.1.0", "eslint-plugin-import": "^2.20.2", - "jest": "^25.2.7" + "jest": "^25.2.7" } } diff --git a/src/components/DivElement.js b/src/components/DivElement.js index 7e22bcb..363d754 100644 --- a/src/components/DivElement.js +++ b/src/components/DivElement.js @@ -1,5 +1,16 @@ // Import HTMLElement here +import HTMLElement from './HTMLElement'; // Define class here +class DivElement extends HTMLElement { + constructor(content) { + super('div', content); + } +} + +const message = new DivElement('It\'s a beautiful life'); +console.log(message.render()); + // Export class here +export { DivElement as default }; diff --git a/src/components/HTMLElement.js b/src/components/HTMLElement.js index 559b785..220f177 100644 --- a/src/components/HTMLElement.js +++ b/src/components/HTMLElement.js @@ -1,4 +1,17 @@ // Define class here +class HTMLElement { + constructor(tag, content) { + this.tag = tag; + this.content = content; + } + + render() { + return `<${this.tag}>${this.content}`; + } +} + +// const htmlElement = new HTMLElement('p', 'Hello World!'); +// console.log(htmlElement.render()); // Export class here -export default {}; +export { HTMLElement as default }; diff --git a/src/rolodex/rolodexPrinter.js b/src/rolodex/rolodexPrinter.js index 0f12389..a431741 100644 --- a/src/rolodex/rolodexPrinter.js +++ b/src/rolodex/rolodexPrinter.js @@ -1,11 +1,11 @@ import people from './people.json'; -people.forEach(function (person) { +people.forEach((person) => { const names = person.name.split(' '); const firstName = names[0]; const lastName = names[1]; - const email = person.email; - const phone = person.phone; + const { email } = person; + const { phone } = person; - console.log('First name: ' + firstName + '\nLast name: ' + lastName + '\nEmail: ' + email + '\nPhone number: ' + phone + '\n'); + console.log(`First name: ${firstName}\nLast name: ${lastName}\nEmail: ${email}\nPhone number: ${phone}\n`); }); diff --git a/src/timer/Timer.js b/src/timer/Timer.js index 2453ed9..ba190bc 100644 --- a/src/timer/Timer.js +++ b/src/timer/Timer.js @@ -1,17 +1,41 @@ -function Timer(seconds) { - this.seconds = seconds; +// function Timer(seconds) { +// this.seconds = seconds; +// console.log(seconds); + +// } + +// Timer.prototype.start = function () { +// var instance = this; +// var timerInterval = setInterval(function () { +// if (instance.seconds === 0) { +// clearInterval(timerInterval); +// } + +// console.log(instance.seconds); +// instance.seconds -= 1; +// }, 0.0000001); +// }; + + +// my code + +class Timer { + constructor(seconds) { + this.seconds = seconds; + console.log(this.seconds); + } + + start() { + const timerInterval = setInterval(() => { + if (this.seconds === 0) { + clearInterval(timerInterval); + } + + console.log(this.seconds); + this.seconds -= 1; + }, 0.0000001); + } } -Timer.prototype.start = function () { - var instance = this; - var timerInterval = setInterval(function () { - if (instance.seconds === 0) { - clearInterval(timerInterval); - } - - console.log(instance.seconds); - instance.seconds -= 1; - }, 1000); -}; export default Timer; diff --git a/src/timer/runTimer.js b/src/timer/runTimer.js index 29db01e..a518919 100644 --- a/src/timer/runTimer.js +++ b/src/timer/runTimer.js @@ -1,4 +1,16 @@ import Timer from './Timer'; -const countdown = new Timer(10); -countdown.start(); +// const countdown = new Timer(10); +// countdown.start(); +// console.log(countdown); + +// const c = () => new Timer(10); +// c.start(); +// console.log(c) + +const f = () => { + const countdown = new Timer(10); + countdown.start(); + console.log(countdown); +}; +f(); diff --git a/test/DivElement.spec.js b/test/DivElement.spec.js index f34069a..3aac7b4 100644 --- a/test/DivElement.spec.js +++ b/test/DivElement.spec.js @@ -9,6 +9,7 @@ describe('DivElement class', () => { }); it('should be a class with the name DivElement', () => { + console.log(instance); expect(instance.constructor.name).toContain('DivElement'); }); From 4fafa60e990073dd896f8ed5226c169df81da878 Mon Sep 17 00:00:00 2001 From: Supriya Puri Date: Mon, 13 Apr 2020 12:38:35 -0700 Subject: [PATCH 2/4] Updated rolodexPrinter for submission. Pre-submission with all tests passed. --- src/components/DivElement.js | 2 -- src/components/HTMLElement.js | 3 --- src/rolodex/rolodexPrinter.js | 7 ++----- src/timer/Timer.js | 22 ---------------------- src/timer/runTimer.js | 8 -------- 5 files changed, 2 insertions(+), 40 deletions(-) diff --git a/src/components/DivElement.js b/src/components/DivElement.js index 363d754..9944c05 100644 --- a/src/components/DivElement.js +++ b/src/components/DivElement.js @@ -9,8 +9,6 @@ class DivElement extends HTMLElement { } } -const message = new DivElement('It\'s a beautiful life'); -console.log(message.render()); // Export class here export { DivElement as default }; diff --git a/src/components/HTMLElement.js b/src/components/HTMLElement.js index 220f177..11a7e38 100644 --- a/src/components/HTMLElement.js +++ b/src/components/HTMLElement.js @@ -10,8 +10,5 @@ class HTMLElement { } } -// const htmlElement = new HTMLElement('p', 'Hello World!'); -// console.log(htmlElement.render()); - // Export class here export { HTMLElement as default }; diff --git a/src/rolodex/rolodexPrinter.js b/src/rolodex/rolodexPrinter.js index a431741..bf6accd 100644 --- a/src/rolodex/rolodexPrinter.js +++ b/src/rolodex/rolodexPrinter.js @@ -1,11 +1,8 @@ import people from './people.json'; people.forEach((person) => { - const names = person.name.split(' '); - const firstName = names[0]; - const lastName = names[1]; - const { email } = person; - const { phone } = person; + const [firstName, lastName] = person.name.split(' '); + const { email, phone } = person; console.log(`First name: ${firstName}\nLast name: ${lastName}\nEmail: ${email}\nPhone number: ${phone}\n`); }); diff --git a/src/timer/Timer.js b/src/timer/Timer.js index ba190bc..656c8ca 100644 --- a/src/timer/Timer.js +++ b/src/timer/Timer.js @@ -1,23 +1,3 @@ -// function Timer(seconds) { -// this.seconds = seconds; -// console.log(seconds); - -// } - -// Timer.prototype.start = function () { -// var instance = this; -// var timerInterval = setInterval(function () { -// if (instance.seconds === 0) { -// clearInterval(timerInterval); -// } - -// console.log(instance.seconds); -// instance.seconds -= 1; -// }, 0.0000001); -// }; - - -// my code class Timer { constructor(seconds) { @@ -30,12 +10,10 @@ class Timer { if (this.seconds === 0) { clearInterval(timerInterval); } - console.log(this.seconds); this.seconds -= 1; }, 0.0000001); } } - export default Timer; diff --git a/src/timer/runTimer.js b/src/timer/runTimer.js index a518919..c054e33 100644 --- a/src/timer/runTimer.js +++ b/src/timer/runTimer.js @@ -1,13 +1,5 @@ import Timer from './Timer'; -// const countdown = new Timer(10); -// countdown.start(); -// console.log(countdown); - -// const c = () => new Timer(10); -// c.start(); -// console.log(c) - const f = () => { const countdown = new Timer(10); countdown.start(); From 692953d577cca26359924b5769fdcc6e44615a50 Mon Sep 17 00:00:00 2001 From: Supriya Puri Date: Mon, 13 Apr 2020 21:07:22 -0700 Subject: [PATCH 3/4] Updated package.json(removing "type": module) --- package.json | 1 - src/timer/runTimer.js | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index b3198df..103b051 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "keywords": [], "author": "", "license": "ISC", - "type": "module", "devDependencies": { "@babel/cli": "^7.8.4", "@babel/core": "^7.9.0", diff --git a/src/timer/runTimer.js b/src/timer/runTimer.js index c054e33..b03f11a 100644 --- a/src/timer/runTimer.js +++ b/src/timer/runTimer.js @@ -1,8 +1,6 @@ import Timer from './Timer'; -const f = () => { const countdown = new Timer(10); countdown.start(); console.log(countdown); -}; -f(); + From 5368571d118b8d0670d66d15a0155c3482ee1338 Mon Sep 17 00:00:00 2001 From: Supriya Puri Date: Mon, 13 Apr 2020 23:19:45 -0700 Subject: [PATCH 4/4] Updating runTimer.js to pass npm test --- src/timer/runTimer.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/timer/runTimer.js b/src/timer/runTimer.js index b03f11a..cdb53e4 100644 --- a/src/timer/runTimer.js +++ b/src/timer/runTimer.js @@ -1,6 +1,5 @@ import Timer from './Timer'; - const countdown = new Timer(10); - countdown.start(); - console.log(countdown); - +const countdown = new Timer(10); +countdown.start(); +console.log(countdown);