Skip to content

casi terminado #1955

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 4 commits into
base: master
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
27 changes: 24 additions & 3 deletions javascript/chronometer.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
class Chronometer {
constructor() {
// ... your code goes here
}

this.currentTime= 0;
this.intervalId= null;

}

start(callback) {
// ... your code goes here
this.intervalId= setInterval(()=> {
this.currentTime= this.currentTime+1 ;
}, 1000);
callback(this.intervalId)

}

getMinutes() {
// ... your code goes here
const minutes= Math.floor (this.currentTime/60);
return minutes
}

getSeconds() {
// ... your code goes here
const seconds= Math.floor(this.currentTime%60);
return seconds
}

computeTwoDigitNumber(value) {
let twoDigits = value.toString();
if (value.length < 2) {
numStr = '0' + numStr;
}
return twoDigits;
// ... your code goes here
}

stop() {
// ... your code goes here
clearInterval(this.intervalId);
this.intervalId= null;
}

reset() {
// ... your code goes here
this.currentTime=0
}

split() {
let split= (this.getMinutes()) + ":"+ (this.getSeconds())
// ... your code goes here
return split
}
}

Expand Down
22 changes: 17 additions & 5 deletions javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ function printTime() {
}

function printMinutes() {
minUniElement.innerText = chronometer.getMinutes()
// ... your code goes here
}

function printSeconds() {
// ... your code goes here
}

// ==> BONUS
function printMilliseconds() {
secUniElement.innerText = chronometer.getSeconds()
// ... your code goes here
}

Expand All @@ -47,6 +44,7 @@ function setSplitBtn() {
}

function setStartBtn() {
chronometer.start()
// ... your code goes here
}

Expand All @@ -56,10 +54,24 @@ function setResetBtn() {

// Start/Stop Button
btnLeftElement.addEventListener('click', () => {
const leftButton = document.getElementById("btnLeft");
const rightButton = document.getElementById("btnRight");
if (leftButton.innerHTML === "START") {
btnLeftElement.addEventListener('click', chronometer.start());
leftButton.innerHTML = "STOP";
rightButton.innerHTML = "SLICE";
} else {
btnLeftElement.addEventListener('click', setStopBtn);
leftButton.innerHTML = "START";
rightButton.innerHTML = "RESET";
}

// ... your code goes here
});

// Reset/Split Button
btnRightElement.addEventListener('click', () => {
// ... your code goes here
});