From d5b04258f5cec44a58c13e00eb9a56fc51e1b056 Mon Sep 17 00:00:00 2001 From: AniVargas Date: Thu, 17 Apr 2025 14:40:10 +0200 Subject: [PATCH 1/4] Update chronometer.js --- javascript/chronometer.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/javascript/chronometer.js b/javascript/chronometer.js index 7a1349680..5a9eeef91 100644 --- a/javascript/chronometer.js +++ b/javascript/chronometer.js @@ -1,34 +1,56 @@ class Chronometer { constructor() { // ... your code goes here - } + this.currentTime= 0; + this.intervalId= null; + + } + start(callback) { - // ... your code goes here + this.currentTime= setInterval(()=> { + this.currentTime= this.currentTime+1 ; + }, 1000); + } getMinutes() { // ... your code goes here + const minutes= Math.floor (this.currentTime/60); + const twoDigitsMin= minutes.padStart(2,"0"); + return twoDigitsMin } - getSeconds() { // ... your code goes here + const seconds= Math.floor(this.currentTime%60); + const twoDigitsSec= seconds.padStart(2,"0"); + return twoDigitsSec } computeTwoDigitNumber(value) { + let twoDigits = value.toString(); + while (value.length < 2) { + numStr = '0' + numStr; + } + return twoDigits; // ... your code goes here } stop() { // ... your code goes here + clearInterval(this.currentTime); + this.intervalId= null; } reset() { // ... your code goes here + this.currentTime=0 } split() { + let split= (minutes) + ":"+ (seconds) // ... your code goes here + return split } } @@ -37,3 +59,4 @@ class Chronometer { if (typeof module !== 'undefined') { module.exports = Chronometer; } + From d5785aa7dd408874913b2327a4c76e664eca5cde Mon Sep 17 00:00:00 2001 From: AniVargas Date: Thu, 17 Apr 2025 14:40:56 +0200 Subject: [PATCH 2/4] Update index.js --- javascript/index.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/javascript/index.js b/javascript/index.js index fb3a43ab4..4da91eb1f 100644 --- a/javascript/index.js +++ b/javascript/index.js @@ -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 } @@ -47,6 +44,7 @@ function setSplitBtn() { } function setStartBtn() { + chronometer.start() // ... your code goes here } @@ -56,6 +54,18 @@ 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 }); @@ -63,3 +73,5 @@ btnLeftElement.addEventListener('click', () => { btnRightElement.addEventListener('click', () => { // ... your code goes here }); + + From e9ea3f13c12cb22d7dcf230d6df01cbfcd85bec4 Mon Sep 17 00:00:00 2001 From: AniVargas Date: Thu, 17 Apr 2025 14:49:38 +0200 Subject: [PATCH 3/4] Update chronometer.js --- javascript/chronometer.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/javascript/chronometer.js b/javascript/chronometer.js index 5a9eeef91..0e1eb3974 100644 --- a/javascript/chronometer.js +++ b/javascript/chronometer.js @@ -8,7 +8,7 @@ class Chronometer { } start(callback) { - this.currentTime= setInterval(()=> { + this.intervalId= setInterval(()=> { this.currentTime= this.currentTime+1 ; }, 1000); @@ -17,8 +17,7 @@ class Chronometer { getMinutes() { // ... your code goes here const minutes= Math.floor (this.currentTime/60); - const twoDigitsMin= minutes.padStart(2,"0"); - return twoDigitsMin + return twoDigitsMin } getSeconds() { // ... your code goes here @@ -30,7 +29,7 @@ class Chronometer { computeTwoDigitNumber(value) { let twoDigits = value.toString(); while (value.length < 2) { - numStr = '0' + numStr; + twoDigits = value.padStart(2,"0") } return twoDigits; // ... your code goes here @@ -38,7 +37,7 @@ class Chronometer { stop() { // ... your code goes here - clearInterval(this.currentTime); + clearInterval(this.intervalId); this.intervalId= null; } @@ -59,4 +58,3 @@ class Chronometer { if (typeof module !== 'undefined') { module.exports = Chronometer; } - From 9b3a8fb6a27a71c9fd8f1bb66fdb4262a0b0b4f8 Mon Sep 17 00:00:00 2001 From: AniVargas Date: Thu, 17 Apr 2025 17:33:10 +0200 Subject: [PATCH 4/4] Update chronometer.js --- javascript/chronometer.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/javascript/chronometer.js b/javascript/chronometer.js index 0e1eb3974..7f886ec1a 100644 --- a/javascript/chronometer.js +++ b/javascript/chronometer.js @@ -11,25 +11,25 @@ class Chronometer { 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 twoDigitsMin + return minutes } getSeconds() { // ... your code goes here const seconds= Math.floor(this.currentTime%60); - const twoDigitsSec= seconds.padStart(2,"0"); - return twoDigitsSec + return seconds } computeTwoDigitNumber(value) { let twoDigits = value.toString(); - while (value.length < 2) { - twoDigits = value.padStart(2,"0") + if (value.length < 2) { + numStr = '0' + numStr; } return twoDigits; // ... your code goes here @@ -47,7 +47,7 @@ class Chronometer { } split() { - let split= (minutes) + ":"+ (seconds) + let split= (this.getMinutes()) + ":"+ (this.getSeconds()) // ... your code goes here return split }