The Training Timer
JavaScript
20 pts
The Training Timer
Build an object timer with label: "Training", seconds: 0, laps: [] and four methods:
tick()adds 1 tothis.seconds,tickMany(n)callsthis.tick()n times (aforloop),lap()pushes the current seconds intothis.laps,printLaps()prints every lap withforEachand an arrow callback that usesthis.label.
Then: call tickMany(3) and lap(); make const tick = timer.tick.bind(timer); and call tick() twice; call lap() again; print Training: 5s and the laps. Expected output:
Training: 5s Training lap 1: 3s Training lap 2: 5s
Checklist
- Give
timerthe four methods, written withthis. - Run the program: 3 ticks, a lap, 2 ticks through a bound copy, another lap.
- Print the laps with
forEachand an arrow callback. - Print the total time and the laps.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
