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
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>Stoplight Exercise</title>
<title>Slave To The Traffic Light</title>
<link rel="stylesheet" href="styles.css" media="screen" title="no title" charset="utf-8">
</head>
<body>
Expand Down
54 changes: 53 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,62 @@
/*
Write JS to make this stoplight work.

var
When I click on the 'stop' button,
the top light should turn red.
When I click on the 'slow' button
the middle light should turn orange.
When I click on the 'go' button
the bottom light should turn green.
*/

var stopButton = document.getElementById('stopButton');
stopButton.addEventListener('click', function(){
if (stopLight.classList.contains('red')){
stopLight.classList.remove('red');
} else if (goLight.classList.contains('green')){
goLight.classList.remove('green');
slowLight.classList.add('yellow');
setTimeout(function(){
slowLight.classList.remove('yellow');
stopLight.classList.add('red');
}, 5000);
}else {
stopLight.classList.add('red');
slowLight.classList.remove('yellow');
goLight.classList.remove('green');
}
});

stopButton.addEventListener('mouseover', function(){
console.log("Entered " + stopButton.innerHTML + " button.");
});

var slowButton = document.getElementById('slowButton');
slowButton.addEventListener('click', function(){
if (slowLight.classList.contains('yellow')){
slowLight.classList.remove('yellow');
} else {
stopLight.classList.remove('red');
slowLight.classList.add('yellow');
goLight.classList.remove('green');
}
});

slowButton.addEventListener('mouseover', function(){
console.log("Entered " + slowButton.innerHTML + " button.");
});

var goButton = document.getElementById('goButton');
goButton.addEventListener('click', function(){
if (goLight.classList.contains('green')){
goLight.classList.remove('green');
} else {
stopLight.classList.remove('red');
slowLight.classList.remove('yellow');
goLight.classList.add('green');
}
});

goButton.addEventListener('mouseover', function(){
console.log("Entered " + goButton.innerHTML + " button.");
});
12 changes: 11 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@
border-radius: 50%;
margin: 25px auto;
transition: background 500ms;
}
}
.red {
background-color:red;
}

.yellow {
background-color:yellow;
}
.green {
background-color:green;
}