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
35 changes: 25 additions & 10 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();
}, 10);

return printTimeCallback;
}

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

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
const newValue = value.toString();

if (newValue.length < 9 || newValue.length >= 0) {
let padTime = "0" + newValue;
return padTime.slice(-2);
}

return newValue;
}

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

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

split() {
// ... your code goes here
}
return `${this.computeTwoDigitNumber(this.getMinutes())}:${this.computeTwoDigitNumber(this.getSeconds())}.${this.computeTwoDigitNumber(this.getCentiseconds())}`;


}
}
38 changes: 29 additions & 9 deletions src/chronometer.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
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();
}, 1000);

return printTimeCallback;
}

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
const newValue = value.toString();

if (newValue.length < 9 || newValue.length >= 0) {
let padTime = "0" + newValue;
return padTime.slice(-2);
}

return newValue;

// if (value >= 0 || value <= 9){
// const padTime = ('0' + value)
// return padTime.slice(-2).toString()
// }
// const result = value.toString();

// return result;
}

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

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

split() {
// ... your code goes here
return `${this.computeTwoDigitNumber(this.getMinutes())}:${this.computeTwoDigitNumber(this.getSeconds())}`
}
}