Skip to content

week1 assignment completed #9

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
10 changes: 8 additions & 2 deletions src/components/DivElement.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Import HTMLElement here

import HTMLElement from './HTMLElement';
// Define class here

class DivElement extends HTMLElement {
constructor(content) {
super('div', content);
this.content = content;
}
}
// Export class here
export { DivElement, HTMLElement };
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;
12 changes: 4 additions & 8 deletions src/rolodex/rolodexPrinter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
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');
people.forEach((person) => {
const { name, email, phone } = person;
const [firstName, lastName] = name.split(' ');
console.log(`First name: ${firstName} \n Last name: ${lastName} \n Email: ${email} \n Phone number: ${phone} \n`);
});
27 changes: 13 additions & 14 deletions src/timer/Timer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
function Timer(seconds) {
this.seconds = seconds;
}

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);
}
this.seconds -= 1;
}, 1000);
}
}

export default Timer;
2 changes: 1 addition & 1 deletion src/timer/runTimer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Timer from './Timer';

const countdown = new Timer(10);
const countdown = new Timer(2);
countdown.start();
2 changes: 1 addition & 1 deletion test/DivElement.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HTMLElement from '../src/components/HTMLElement';
import DivElement from '../src/components/DivElement';
import {DivElement} from '../src/components/DivElement';

describe('DivElement class', () => {
let instance;
Expand Down