From ba764541e2bb80944b0db68c86e97f0263e2da70 Mon Sep 17 00:00:00 2001 From: Ryan Sobol Date: Fri, 11 Nov 2016 06:52:25 -0800 Subject: [PATCH] Improve the solution --- index.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 1f89523..95c56a3 100644 --- a/index.js +++ b/index.js @@ -31,29 +31,21 @@ }); // part 2 - stopButton.addEventListener('mouseenter', (event) => { + const handleMouseEnter = function(event) { console.log(`Entered ${event.target.textContent} button`); - }); - - stopButton.addEventListener('mouseleave', (event) => { - console.log(`Left ${event.target.textContent} button`); - }); - - slowButton.addEventListener('mouseenter', (event) => { - console.log(`Entered ${event.target.textContent} button`); - }); + }; - slowButton.addEventListener('mouseleave', (event) => { + const handleMouseLeave = function(event) { console.log(`Left ${event.target.textContent} button`); - }); + }; - goButton.addEventListener('mouseenter', (event) => { - console.log(`Entered ${event.target.textContent} button`); - }); + stopButton.addEventListener('mouseenter', handleMouseEnter); + slowButton.addEventListener('mouseenter', handleMouseEnter); + goButton.addEventListener('mouseenter', handleMouseEnter); - goButton.addEventListener('mouseleave', (event) => { - console.log(`Left ${event.target.textContent} button`); - }); + stopButton.addEventListener('mouseleave', handleMouseLeave); + slowButton.addEventListener('mouseleave', handleMouseLeave); + goButton.addEventListener('mouseleave', handleMouseLeave); // bonus controls.addEventListener('click', (event) => {