Improve the solution

solution
Ryan Sobol 8 years ago
parent 0336132c61
commit 43488eeaea
  1. 17
      index.js

@ -12,6 +12,15 @@
// part 1 // part 1
stopButton.addEventListener('click', () => { stopButton.addEventListener('click', () => {
stopLight.classList.toggle('stop'); stopLight.classList.toggle('stop');
// or...
// if (stopLight.classList.contains('stop')) {
// stopLight.classList.remove('stop');
// }
// else {
// stopLight.classList.add('stop');
// }
}); });
slowButton.addEventListener('click', () => { slowButton.addEventListener('click', () => {
@ -51,6 +60,14 @@
if (event.target === stopButton) { if (event.target === stopButton) {
status = stopLight.classList.contains('stop') ? 'on' : 'off'; status = stopLight.classList.contains('stop') ? 'on' : 'off';
// or...
// if (stopLight.classList.contains('stop')) {
// status = 'on';
// }
// else {
// status = 'off';
// }
} }
else if (event.target === slowButton) { else if (event.target === slowButton) {
status = slowLight.classList.contains('slow') ? 'on' : 'off'; status = slowLight.classList.contains('slow') ? 'on' : 'off';

Loading…
Cancel
Save