From 379d77a76df9b735a29bd6e5d571348956a0b515 Mon Sep 17 00:00:00 2001 From: Sven Otto Date: Sat, 11 Apr 2020 10:29:39 -0700 Subject: [PATCH 1/2] week 1 homework --- src/components/DivElement.js | 12 ++++++++++ src/components/HTMLElement.js | 15 +++++++++++- src/rolodex/rolodexPrinter.js | 24 ++++++++++++++----- src/timer/Timer.js | 44 ++++++++++++++++++++++++----------- 4 files changed, 75 insertions(+), 20 deletions(-) diff --git a/src/components/DivElement.js b/src/components/DivElement.js index 7e22bcb..5c6d34e 100644 --- a/src/components/DivElement.js +++ b/src/components/DivElement.js @@ -1,5 +1,17 @@ // Import HTMLElement here +import HTMLElement from './HTMLElement'; // Define class here +class DivElement extends HTMLElement { + constructor (content) { + super(content); + this.content = content; + this.tag = 'div'; + } +} // Export class here +export default DivElement; + +// const andIThinkToMyself = new DivElement('What a wonderful world'); +// console.log(andIThinkToMyself.render()); diff --git a/src/components/HTMLElement.js b/src/components/HTMLElement.js index 559b785..69091e9 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}`; + } +} // Export class here -export default {}; +export default HTMLElement; + +// const lovelaceQuote = new HTMLElement('p', 'I am never so happy as when I am really engaged in good earnest...'); +// console.log(lovelaceQuote.render()); diff --git a/src/rolodex/rolodexPrinter.js b/src/rolodex/rolodexPrinter.js index 0f12389..fdb17c0 100644 --- a/src/rolodex/rolodexPrinter.js +++ b/src/rolodex/rolodexPrinter.js @@ -1,11 +1,23 @@ +// Old Code +// import people from './people.json'; + +// people.forEach(function (person) { +// const names = person.name.split(' '); +// const firstName = names[0]; +// const lastName = names[1]; +// const email = person.email; +// const phone = person.phone; + +// console.log('First name: ' + firstName + '\nLast name: ' + lastName + '\nEmail: ' + email + '\nPhone number: ' + phone + '\n'); +// }); + +// New Code import people from './people.json'; people.forEach(function (person) { - const names = person.name.split(' '); - const firstName = names[0]; - const lastName = names[1]; - const email = person.email; - const phone = person.phone; + const names = person.name.split(' '); + const [firstName, lastName] = [names[0], names[1]]; + const { email, phone } = person; - console.log('First name: ' + firstName + '\nLast name: ' + lastName + '\nEmail: ' + email + '\nPhone number: ' + phone + '\n'); + console.log(`First name: ${firstName} Last name: ${lastName} Email: ${email} Phone number: ${phone}`); }); diff --git a/src/timer/Timer.js b/src/timer/Timer.js index 2453ed9..cf34acf 100644 --- a/src/timer/Timer.js +++ b/src/timer/Timer.js @@ -1,17 +1,35 @@ -function Timer(seconds) { - this.seconds = seconds; -} +// function Timer(seconds) { +// this.seconds = 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; +// }, 1000); +// }; -Timer.prototype.start = function () { - var instance = this; - var timerInterval = setInterval(function () { - if (instance.seconds === 0) { - clearInterval(timerInterval); - } +class Timer { + constructor (seconds) { + this.seconds = seconds; + } - console.log(instance.seconds); - instance.seconds -= 1; - }, 1000); -}; + start () { + const timerInterval = setInterval(() => { + if (this.seconds === 0) { + clearInterval(timerInterval); + } + + console.log(this.seconds); + this.seconds -= 1; + + }, 1000); + } +} export default Timer; From e0b7b0c86ce8537c5747203b3e2e591e2f2279a4 Mon Sep 17 00:00:00 2001 From: Sven Otto Date: Sun, 12 Apr 2020 08:35:06 -0700 Subject: [PATCH 2/2] linted code --- package-lock.json | 6 +++--- src/components/DivElement.js | 13 +++++-------- src/components/HTMLElement.js | 17 +++++++---------- src/rolodex/rolodexPrinter.js | 22 ++++------------------ src/timer/Timer.js | 25 ++++++++++++------------- 5 files changed, 31 insertions(+), 52 deletions(-) diff --git a/package-lock.json b/package-lock.json index 749b59f..6ba1584 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8131,9 +8131,9 @@ "dev": true }, "strip-json-comments": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.0.1.tgz", - "integrity": "sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.0.tgz", + "integrity": "sha512-e6/d0eBu7gHtdCqFt0xJr642LdToM5/cN4Qb9DbHjVx1CP5RyeM+zH7pbecEmDv/lBqb0QH+6Uqq75rxFPkM0w==", "dev": true }, "supports-color": { diff --git a/src/components/DivElement.js b/src/components/DivElement.js index 5c6d34e..8073732 100644 --- a/src/components/DivElement.js +++ b/src/components/DivElement.js @@ -3,15 +3,12 @@ import HTMLElement from './HTMLElement'; // Define class here class DivElement extends HTMLElement { - constructor (content) { - super(content); - this.content = content; - this.tag = 'div'; - } + constructor(content) { + super(content); + this.content = content; + this.tag = 'div'; + } } // Export class here export default DivElement; - -// const andIThinkToMyself = new DivElement('What a wonderful world'); -// console.log(andIThinkToMyself.render()); diff --git a/src/components/HTMLElement.js b/src/components/HTMLElement.js index 69091e9..f96ac6d 100644 --- a/src/components/HTMLElement.js +++ b/src/components/HTMLElement.js @@ -1,17 +1,14 @@ // Define class here class HTMLElement { - constructor (tag, content) { - this.tag = tag; - this.content = content; - } + constructor(tag, content) { + this.tag = tag; + this.content = content; + } - render () { - return `<${this.tag}>${this.content}`; - } + render() { + return `<${this.tag}>${this.content}`; + } } // Export class here export default HTMLElement; - -// const lovelaceQuote = new HTMLElement('p', 'I am never so happy as when I am really engaged in good earnest...'); -// console.log(lovelaceQuote.render()); diff --git a/src/rolodex/rolodexPrinter.js b/src/rolodex/rolodexPrinter.js index fdb17c0..09f5b41 100644 --- a/src/rolodex/rolodexPrinter.js +++ b/src/rolodex/rolodexPrinter.js @@ -1,23 +1,9 @@ -// Old Code -// import people from './people.json'; - -// people.forEach(function (person) { -// const names = person.name.split(' '); -// const firstName = names[0]; -// const lastName = names[1]; -// const email = person.email; -// const phone = person.phone; - -// console.log('First name: ' + firstName + '\nLast name: ' + lastName + '\nEmail: ' + email + '\nPhone number: ' + phone + '\n'); -// }); - -// New Code import people from './people.json'; -people.forEach(function (person) { - const names = person.name.split(' '); - const [firstName, lastName] = [names[0], names[1]]; - const { email, phone } = person; +people.forEach((person) => { + const names = person.name.split(' '); + const [firstName, lastName] = [names[0], names[1]]; + const { email, phone } = person; console.log(`First name: ${firstName} Last name: ${lastName} Email: ${email} Phone number: ${phone}`); }); diff --git a/src/timer/Timer.js b/src/timer/Timer.js index cf34acf..5e5eb61 100644 --- a/src/timer/Timer.js +++ b/src/timer/Timer.js @@ -15,21 +15,20 @@ // }; class Timer { - constructor (seconds) { - this.seconds = seconds; - } + constructor(seconds) { + this.seconds = seconds; + } - start () { - const timerInterval = setInterval(() => { - if (this.seconds === 0) { - clearInterval(timerInterval); - } + start() { + const timerInterval = setInterval(() => { + if (this.seconds === 0) { + clearInterval(timerInterval); + } - console.log(this.seconds); - this.seconds -= 1; - - }, 1000); - } + console.log(this.seconds); + this.seconds -= 1; + }, 1000); + } } export default Timer;