Skip to content
Open

timer #164

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
11 changes: 7 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<title>i &hearts; js</title>
<title>Eriks Stop Watch</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>
<body>

<h1 id="timer">Stop Watch</h1>

<h1 id="timer">0</h1>
<div class="controls">
<button id="reset">Reset</button>
<button id="start">Start</button>
<button id="pause">Pause</button>
</div>

</body>
<p>ERIK'S STOP WATCH TIMER</p>
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQtxoP7rBxv2XmP-MXjnwJ-1mvowNw8YQdHU4VayM7YSIRu_E33"</img>
<script src="timers.js"></script>
</body>

</html>
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Spend 10 minutes looking at [JavaScript Timers](https://developer.mozilla.org/en

####Take It Step By Step

This is a tough assignment, so don't stress over meeting all the requirements. Just take it step by step and try to meet the benchmarks below in order.
This is a tough assignment, so don't stress over meeting all the requirements. Just take it step by step and try to meet the benchmarks below in order.

1. Create Javascript selectors that target each of the timer buttons.
2. Create click handlers (empty, for now) for each of the timer buttons.
Expand Down
30 changes: 26 additions & 4 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,44 @@ h1 {
font-family: Josefin Slab;
font-size: 72px;
text-align: center;
color: red;
border-bottom: 10px solid black;
text-shadow: 4px 0px black;
}

button {
background: #4479BA;
color: #FFF;
background: green;
color: black;
font-family: Josefin Slab;
font-size: 50px;
text-align: center;
border: 1px solid black;
border: 10px solid black;
margin: 20px;
padding: 15px 25px;
border-radius: 10px;
box-shadow: 2px 2px black;
text-decoration: underline;
}

button:hover{
background: #356094;
background: red;
}

body {
background-image: url("file:///Users/Erik/Desktop/IMG_9438.jpg");
background-position: center;
background-repeat: no-repeat;
background-color: black;
}

p {
text-align: center;
color: red;
font-size: 40px;
text-shadow: 4px 0px black;
}

img {
display: block;
margin-left: auto;
margin-right: auto }
39 changes: 39 additions & 0 deletions timers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
let timer = {
seconds: 0,
timerId: 0,
run: false,

clock: {
timer: $("#timer"),
reset: $("#reset"),
start: $("#start"),
pause: $("#pause"),
},

updateTime: function updateTime(){
this.seconds++;
this.clock.timer.text('Time elapsed: ' + this.seconds);
},

setupListeners: function () {
this.clock.start.on('click', function() {
console.log('start');
this.clock.timer.text('Time elapsed: ' + this.seconds);
if (this.run === false){
this.timerId = setInterval(this.updateTime.bind(this), 1000);
this.run = true;
}
}.bind(this));

this.clock.pause.on('click', function() {
clearInterval(this.timerId);
this.run = false;
}.bind(this));

this.clock.reset.on('click', function() {
this.seconds = 0;
console.log('reset ' + this.seconds);
clearInterval(this.timerId);
this.run = false;
this.clock.timer.text('Stop Watch');
}.bind(this));
}
}

timer.setupListeners();