Skip to content

Homework 01 #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/components/DivElement.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
// Import HTMLElement here
import HTMLElement from './HTMLElement';

// Define class here
class DivElement extends HTMLElement {
constructor(content) {
super('div', content);
}

render() {
// Instructions unclear.
// Sounds like this is what you want:
return `<${this.tag}>${this.content}</${this.tag}>`;

// Easier if it was
// return super.render();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class should inherit the render function in the parent class (do not override it, aka define it in DivElement).

Since DivElement inherits from HTMLElement, the render function doesn't need to be defined. It's inherited from HTMLElement. This would be an "override". See: https://javascript.info/class-inheritance#overriding-a-method

}

// Export class here
export default DivElement;
12 changes: 11 additions & 1 deletion src/components/HTMLElement.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
// Define class here
class HTMLElement {
constructor(tag, content) {
this.tag = tag;
this.content = content;
}

render() {
return `<${this.tag}>${this.content}</${this.tag}>`;
}
}

// Export class here
export default {};
export default HTMLElement;
11 changes: 4 additions & 7 deletions src/rolodex/rolodexPrinter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
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;
people.forEach((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');
console.log(`First name: ${firstName}\nLast name: ${lastName}\nEmail: ${email}\nPhone number: ${phone}\n`);
});
28 changes: 15 additions & 13 deletions src/timer/Timer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
function Timer(seconds) {
this.seconds = seconds;
}
class Timer {
constructor(seconds) {
this.seconds = seconds;
}

Timer.prototype.start = function () {
var instance = this;
var timerInterval = setInterval(function () {
if (instance.seconds === 0) {
clearInterval(timerInterval);
}
start() {
let instance = this.seconds;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor the code to avoid assigning this to a variable.

instance on line 9 could be replaced with this.seconds. Although this technically meets the requirement in the README.

const timerInterval = setInterval(() => {
if (instance === 0) {
clearInterval(timerInterval);
}

console.log(instance.seconds);
instance.seconds -= 1;
}, 1000);
};
console.log(instance);
instance -= 1; // the linter does not like "instance--". WTF?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Airbnb lint rules probably disallowed this due to this weirdness in JavaScript with -- and spacing: https://eslint.org/docs/rules/no-plusplus

}, 1000);
}
}

export default Timer;