From 139798cc0755caa25a54151159b823f0d59c66a9 Mon Sep 17 00:00:00 2001 From: Matt Lane Date: Wed, 24 Feb 2016 14:40:24 -0800 Subject: [PATCH 1/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 639c2fb..f03d5fd 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,6 @@ Afterwards: 8. When the reset button is clicked - remove the `selected` class from each `
  • `, change the image to `panic.jpeg`, and add the gray div back to the DOM if it has been removed. -9. When the a, e, i, o, or u key is pressed, the page alerts the message "I HATE VOWELS!" +9. When the 1, 2, 3, 4, 5, 6, 7, 8, 9, or 0 key is pressed, the page alerts the message "I HATE NUMBERZZZ!" -BONUS: If someone types the [Konami Code](https://en.wikipedia.org/wiki/Konami_Code), the page alerts "YOU ARE AN EVENT HANDLER GURUUUUUUUUU!" \ No newline at end of file +BONUS: If someone types the [Konami Code](https://en.wikipedia.org/wiki/Konami_Code), the page alerts "YOU ARE AN EVENT HANDLER GURUUUUUUUUU!" From 4168c3ca1dac5f8258e13c902919475a5f7e33e2 Mon Sep 17 00:00:00 2001 From: Matt Lane Date: Wed, 24 Feb 2016 15:50:48 -0800 Subject: [PATCH 2/5] Update app.js --- app.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app.js b/app.js index f2b6cae..f09cb70 100644 --- a/app.js +++ b/app.js @@ -1,7 +1 @@ console.log("Javascript is alive!"); - -window.onload = function() { - document.querySelector('body').addEventListener('keypress', function(e) { - console.log(e) - }) -}; \ No newline at end of file From 7957874f098dd9d9375021190bdc6c0136c5309a Mon Sep 17 00:00:00 2001 From: Matt Lane Date: Wed, 24 Feb 2016 17:03:58 -0800 Subject: [PATCH 3/5] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index f03d5fd..1ae221b 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,7 @@ Afterwards: 7. When the orange div is moused over, its width doubles. When the mouse moves out of the div, it returns to its original size. -8. When the reset button is clicked - remove the `selected` class from - each `
  • `, change the image to `panic.jpeg`, and add the gray div back to the DOM if it has been removed. +8. When the reset button is clicked - remove the `selected` class from each `
  • ` and change the image to `panic.jpeg`. 9. When the 1, 2, 3, 4, 5, 6, 7, 8, 9, or 0 key is pressed, the page alerts the message "I HATE NUMBERZZZ!" From 926029a8e6995f0f938ba9b5c5f58b1391e5a47f Mon Sep 17 00:00:00 2001 From: Alexander Chang Date: Thu, 25 Feb 2016 22:32:16 -0800 Subject: [PATCH 4/5] completed app.js assignment --- app.js | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index f09cb70..09ce4eb 100644 --- a/app.js +++ b/app.js @@ -1 +1,88 @@ -console.log("Javascript is alive!"); +document.addEventListener('DOMContentLoaded', function() { + + var imgArray = ['./images/milk.jpeg','./images/honey.jpeg','./images/water.jpeg','./images/wine.jpeg','./images/beer.jpeg']; + + var greeting = document.getElementById("greeting"); + greeting.innerText = "Hello, World!"; + + var li = document.querySelectorAll("li"); + for (var i = 0; i < li.length; i++) { + li[i].style.backgroundColor = "yellow"; + } + + var imgChange = document.querySelector("img"); + var img = document.createElement("img"); + img.src = "http://49.media.tumblr.com/tumblr_m6qt1rjPSz1rxjzkho1_500.gif"; + greeting.appendChild(img); + + + var ul = document.getElementsByTagName("ul"); + function selected(event) { + for (var j = 0; j < li.length; j++) { + li[j].classList.remove("selected"); + } + event.target.classList.add("selected"); + + for (var k = 0; k < li.length; k++) { + if (li[k].className === "selected") { + imgChange.src = imgArray[k]; + } + } + event.target.classList.add("selected"); + } + ul[0].addEventListener("click", selected); + + + var ghosting = document.getElementById("ghosting"); + function spooky() { + this.remove(); + } + ghosting.addEventListener("mouseenter", spooky); + + //how to not hard-code width change? + var resize = document.getElementById("resize"); + function bigger() { + // var curr_width = parseInt(this.style.width); this.style.width returns "" + // this.style.width = {curr_width * 2} + "px"; + this.style.width = "400px"; + } + resize.addEventListener("mouseenter", bigger); + + function smaller() { + // var curr_width = parseInt(this.style.width); + // this.style.width = {curr_width / 2} + "px"; + this.style.width = "200px"; + } + resize.addEventListener("mouseleave", smaller); + + var button = document.getElementById("reset"); + function reset() { + for (var j = 0; j < li.length; j++) { + li[j].classList.remove("selected"); + imgChange.src = './images/panic.jpeg'; + } + } + button.addEventListener("click", reset); + + window.addEventListener("keypress", function(event) { + if (event.keyCode >= 48 && event.keyCode <= 57) { + alert("I HATE NUMBERZZZ!"); + } + }); + + var combo = []; + window.addEventListener("keyup", function(event) { + + if (combo.length == 10) { + combo.shift(); + combo.push(event.keyCode); + } else combo.push(event.keyCode); + + var comboStr = ""; + for (var i = 0; i < combo.length; i++) { + comboStr += combo[i]; + } + if (comboStr === "38384040373937396665") alert("YOU ARE AN EVENT HANDLER GURUUUUUUUUU!"); + }); + +}); \ No newline at end of file From 0c9a9c73d23eef8301850cd2560b1ecf27d45ff0 Mon Sep 17 00:00:00 2001 From: Alexander Chang Date: Fri, 26 Feb 2016 20:33:24 -0800 Subject: [PATCH 5/5] updated bonus solution --- app.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index 8777300..b5fd387 100644 --- a/app.js +++ b/app.js @@ -56,18 +56,21 @@ var noDigits = function(e) { // BONUS -var idx = 0; +var code = []; var konamiCheck = function(e) { - var konamiCodeKeyCodes = [38,38,40,40,37,39,37,39,66,65]; - if (e.keyCode === konamiCodeKeyCodes[idx]) { - idx++; - if (idx === konamiCodeKeyCodes.length) { - alert("YOU ARE AN EVENT HANDLER GURUUUUUUUUU!"); - idx = 0; - } - } else { - idx = 0; - } + var konamiCodeKeyCodes = "38384040373937396665"; + + if (code.length == 10) { + code.shift(); + code.push(e.keyCode); + } else code.push(e.keyCode); + var codeStr = ""; + for (var i = 0; i < code.length; i++) { + codeStr += code[i]; + } + if (codeStr === konamiCodeKeyCodes) { + alert("YOU ARE AN EVENT HANDLER GURUUUUUUUUU!"); + } }; \ No newline at end of file