Skip to content
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
34 changes: 18 additions & 16 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
let startBtn = document.querySelector('#start')
let stopBtn = document.querySelector('#stop')
let timeDOM = document.querySelector('#timer')

let startBtn = document.querySelector("#start");
let stopBtn = document.querySelector("#stop");
let timeDOM = document.querySelector("#timer");

// STEP 3: Create an object from the timer class

function updateTime(){
// update the time DOM here
// console.log('Here')

}

let timeObj = new Timer();

startBtn.addEventListener('click', () => {
// Call the timer start method
})
function updateTime() {
// update the time DOM here
// console.log('Here')
timeDOM.textContent = timeObj.time;
}

startBtn.addEventListener("click", () => {
// Call the timer start method
timeObj.start();
updateTime(); //callback
});

stopBtn.addEventListener('click', () => {
// Call the timer stop method
})
stopBtn.addEventListener("click", () => {
// Call the timer stop method
timeObj.stop();
});
33 changes: 17 additions & 16 deletions timer.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// add properties and methods for your timer here
class Timer {
//STEP 0: Add necessary properties for your timer
constructor(){
this.time = 0;
this.intervalID = 0;
}
//STEP 0: Add necessary properties for your timer
constructor() {
this.time = 0;
this.intervalID = 0;
}

// STEP1: Create a start method to start the timer
start(callback){

}
// STEP1: Create a start method to start the timer
start(callback) {
this.intervalID = setInterval(() => {
this.time = this.time + 1;
updateTime(); //callback update
}, 1000);
}


// STEP2: Create a stop method to stop the timer
stop(){

}

}
// STEP2: Create a stop method to stop the timer
stop() {
clearInterval(this.intervalID);
}
}