Skip to content

Added all HW Responses #14

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 1 commit 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
10 changes: 10 additions & 0 deletions src/components/DivElement.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Import HTMLElement here
import HTMLElement from './HTMLElement';

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

// let div1 = new DivElement('test');
// console.log(div1);
// console.log(div1.render());
// Export class here
export default DivElement;
16 changes: 15 additions & 1 deletion src/components/HTMLElement.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// Define class here
class HTMLElement {
constructor(tag, content) {
this.tag = tag;
this.content = content;
}

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

// const p = new HTMLElement('p','heyyyy');
// console.log(p.render());

// console.log(p);
// Export class here
export default {};
export default HTMLElement;
24 changes: 18 additions & 6 deletions src/rolodex/rolodexPrinter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import people from './people.json';

const{name, email, phone} = person;
Copy link
Contributor

Choose a reason for hiding this comment

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

person is out of scope here, so this will cause an error because the variable is not defined.


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;
firstName = person.name;
lastName = person.name;
email = person.email;
phone = person.phone;

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' `);
Copy link
Contributor

Choose a reason for hiding this comment

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

Template literal looks good.

});

// 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');
// });
Copy link
Contributor

Choose a reason for hiding this comment

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

To get this working, you can just use this code + replace the console.log line with your correct template literal version. Then make the following changes:

  1. Since names is an array, you can destructure the first/last names like this: const [ firstName, lastName ] = person.name.split(' ');
  2. Since email and phone are properties being pulled out of the person object, they can be destructured as well, like this: const { email, phone} = person;.

Hopefully that helps.


37 changes: 25 additions & 12 deletions src/timer/Timer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
function Timer(seconds) {
this.seconds = seconds;
class Timer {
constructor(seconds) {
this.seconds = seconds;
}

start() {
const timerInterval = setInterval(() => {
if (this.seconds === 0) {
clearInterval(timerInterval);
}

console.log(this.seconds);
this.seconds -= 1;
}, 1000);
}
}

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

console.log(instance.seconds);
instance.seconds -= 1;
}, 1000);
};
// console.log(instance.seconds);
// instance.seconds -= 1;
// }, 1000);
// };

export default Timer;