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
8 changes: 4 additions & 4 deletions SpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<script src="jasmine/jasmine-2.8.0/boot.js"></script>

<!-- Iterations 1 - 8 -->
<script src="src/chronometer.js"></script>
<script src="tests/chronometer.spec.js"></script>
<!-- <script src="src/chronometer.js"></script> -->
<!-- <script src="tests/chronometer.spec.js"></script> -->

<!-- Bonus Iteration 9: Centiseconds -->
<!-- <script src="src/chronometer-centiseconds.js"></script> -->
<!-- <script src="tests/chronometer-centiseconds.spec.js"></script> -->
<script src="src/chronometer-centiseconds.js"></script>
<script src="tests/chronometer-centiseconds.spec.js"></script>

</head>

Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ <h3>Splits</h3>


<!-- Iterations 1 - 8 -->
<script src="src/chronometer.js"></script>
<!-- <script src="src/chronometer.js"></script> -->

<!-- Bonus Iteration 9: Centiseconds -->
<!-- <script src="src/chronometer-centiseconds.js"></script> -->
<script src="src/chronometer-centiseconds.js"></script>


<!-- DOM manipulation logic -->
Expand Down
15 changes: 15 additions & 0 deletions src/chronometer-centiseconds.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
class Chronometer {
constructor() {
// ... your code goes here
this.currentTime = 0;
this.intervalId = null;
}

start(printTimeCallback) {
// ... your code goes here
this.intervalId = setInterval(() => {
this.currentTime++;
if (printTimeCallback) printTimeCallback(this.currentTime);
}, 10);
}

getMinutes() {
// ... your code goes here
return Math.floor(this.currentTime / (60*100));

}

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

getCentiseconds() {
// ... your code goes here
return Math.floor(this.currentTime%100 );

}

computeTwoDigitNumber(value) {
// ... your code goes here
return value < 10 ? `0${value}` :`${value}`;
}

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

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

split() {
// ... your code goes here
return `${this.computeTwoDigitNumber(this.getMinutes())}:${this.computeTwoDigitNumber(this.getSeconds())}.${this.computeTwoDigitNumber(this.getCentiseconds())}`;
}
}
12 changes: 12 additions & 0 deletions src/chronometer.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
class Chronometer {
constructor() {
// ... your code goes here
this.currentTime = 0;
this.intervalId = null;
}

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

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

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

computeTwoDigitNumber(value) {
// ... your code goes here
return value < 10 ? `0${value}` :`${value}`;
}

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

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

split() {
// ... your code goes here
return `${this.computeTwoDigitNumber(this.getMinutes())}:${this.computeTwoDigitNumber(this.getSeconds())}`;
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ btnRight.addEventListener('click', () => {
} else {
printSplit();
}
});
});