all except bonus
This commit is contained in:
parent
ed0de11490
commit
a52d23074a
@ -22,9 +22,8 @@ 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.
|
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
|
8. When the reset button is clicked - remove the `selected` class from each `<li>` and change the image to `panic.jpeg`.
|
||||||
each `<li>`, 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!"
|
BONUS: If someone types the [Konami Code](https://en.wikipedia.org/wiki/Konami_Code), the page alerts "YOU ARE AN EVENT HANDLER GURUUUUUUUUU!"
|
43
app.js
43
app.js
@ -1,21 +1,26 @@
|
|||||||
|
var changeGreetingAndAddGif = function(){
|
||||||
|
var greeting_div = document.getElementById("greeting");
|
||||||
|
greeting_div.innerHTML = "Hello, World!";
|
||||||
|
var img = document.createElement('img');
|
||||||
|
img.src = "http://49.media.tumblr.com/tumblr_m6qt1rjPSz1rxjzkho1_500.gif";
|
||||||
|
greeting_div.appendChild(img);
|
||||||
|
};
|
||||||
|
|
||||||
var styleListElements = function(){
|
var styleListElements = function(){
|
||||||
var list_items = document.querySelectorAll("div#essentials > ul > li");
|
var list_items = document.querySelectorAll("div#essentials > ul > li");
|
||||||
for (var i = list_items.length - 1; i >= 0; i--) {
|
for (var i = list_items.length - 1; i >= 0; i--) {
|
||||||
// for (initializer, condition, counter)
|
|
||||||
list_items[i].style.backgroundColor = "yellow";
|
list_items[i].style.backgroundColor = "yellow";
|
||||||
list_items[i].addEventListener("click", selectItem);
|
list_items[i].addEventListener("click", selectItem);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var selectItem = function(event){
|
var selectItem = function(event){
|
||||||
// console.log(this.innerHTML);
|
var list_items = document.querySelectorAll("div#essentials > ul > li");
|
||||||
|
for (var i = list_items.length - 1; i >= 0; i--) {
|
||||||
|
list_items[i].classList.remove("selected");
|
||||||
|
}
|
||||||
this.classList.add("selected");
|
this.classList.add("selected");
|
||||||
document.querySelector("img").setAttribute("src","./images/" + this.innerHTML + ".jpeg");
|
document.querySelectorAll("img")[1].setAttribute("src","./images/" + this.innerHTML + ".jpeg");
|
||||||
};
|
|
||||||
|
|
||||||
var changeGreeting = function(){
|
|
||||||
var greeting_div = document.getElementById("greeting");
|
|
||||||
greeting_div.innerHTML = "Hello Planet earth!";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var resetButtonHandler = function() {
|
var resetButtonHandler = function() {
|
||||||
@ -23,13 +28,31 @@ var resetButtonHandler = function() {
|
|||||||
for (var i = list_items.length - 1; i >= 0; i--) {
|
for (var i = list_items.length - 1; i >= 0; i--) {
|
||||||
list_items[i].className = "";
|
list_items[i].className = "";
|
||||||
}
|
}
|
||||||
document.querySelector("img").setAttribute("src","./images/panic.jpeg");
|
document.querySelectorAll("img")[1].setAttribute("src","./images/panic.jpeg");
|
||||||
|
};
|
||||||
|
|
||||||
|
var doubleWidth = function() {
|
||||||
|
this.style.width = '400px';
|
||||||
|
};
|
||||||
|
|
||||||
|
var resetWidth = function() {
|
||||||
|
this.style.width = '200px';
|
||||||
|
};
|
||||||
|
|
||||||
|
var noDigits = function(e) {
|
||||||
|
if (e.keyCode >= 48 && e.keyCode <= 57) {
|
||||||
|
alert("I HATE NUMBERZZZ!");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var initialize = function(){
|
var initialize = function(){
|
||||||
changeGreeting();
|
changeGreetingAndAddGif();
|
||||||
styleListElements();
|
styleListElements();
|
||||||
document.querySelector("#reset").addEventListener("click",resetButtonHandler);
|
document.querySelector("#reset").addEventListener("click",resetButtonHandler);
|
||||||
|
document.querySelector("#ghosting").addEventListener("mouseover", function() { this.remove(); });
|
||||||
|
document.querySelector("#resize").addEventListener("mouseenter", doubleWidth);
|
||||||
|
document.querySelector("#resize").addEventListener("mouseleave", resetWidth);
|
||||||
|
document.querySelector("body").addEventListener("keypress", noDigits);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.onload=initialize;
|
window.onload=initialize;
|
Loading…
x
Reference in New Issue
Block a user