diff --git a/Week1/exercise/w1/index.js b/Week1/exercise/w1/index.js index fcea7032e..290a10745 100644 --- a/Week1/exercise/w1/index.js +++ b/Week1/exercise/w1/index.js @@ -1,19 +1,34 @@ console.log('Hack your future Belgium!'); +function changeHeader() { + console.log('test'); + header.innerHTML = 'ramzi'; +} +const header = document.querySelector('h1'); + +header.addEventListener('click', changeHeader); +document.getElementById('btn-header').addEventListener('click', changeHeader); // EXERCISE 1 -// 1a: create a function called "changeHeader", put a console.log() inside this function to test +// 1a: create a functi[on called "changeHeader", put a console.log() inside this function to test -// 1d: add an event listener to the "Change header" button +// 1d: add an event listener to the "Change header" button // and call the "changeHeader" function when clicked ( you should see your console.log() ) // 1b: inside this function: select the header element and assign that to a variable called "header" // 1c: change the inner html of the header element to your name - // ====================================== // +function changeImage() { + var imageInputValue = document.getElementById('imageInput'); + var imageToChange = document.querySelector('img'); + console.dir(imageInputValue); + imageToChange.src = imageInputValue.value; +} + +document.getElementById('btn-changeImage').addEventListener('click', changeImage); // EXERCISE 2 @@ -29,9 +44,19 @@ console.log('Hack your future Belgium!'); // 2e: to change the image: assign the imageInputValue to the image src - // ====================================== // +function addTodo() { + var todolist = document.getElementById('todoList'); + var todo_input = document.querySelector('#todoInput'); + //the above one its the same of document.getElementById ('todoInput') + console.log(todoInput.value); + var element_li = document.createElement('li'); + element_li.innerHTML = todo_input.value; + todolist.appendChild(element_li); +} + +document.getElementById('btn-addTodo').addEventListener('click', addTodo); // Exercise 3: diff --git a/Week1/homework/app.js b/Week1/homework/app.js index a9b5f75d8..df5ee07f9 100644 --- a/Week1/homework/app.js +++ b/Week1/homework/app.js @@ -3,9 +3,103 @@ { const bookTitles = [ // Replace with your own book titles - 'harry_potter_chamber_secrets', + 'brave_new_world', + 'the_moonstone', + 'little_women', + 'three_men_in_boat', + 'the_sign_of_four', + 'new_grub_street', + 'jude_the_obscure', + 'heart_of_darkness', + 'sister_carrie', + 'the_rainbow', ]; + const bookData = { + brave_new_world: { + title: 'Brave new world', + author: 'Aldous Huxley', + language: 'English', + image: './images/brave_new_world.jpg', + }, + the_moonstone: { + title: 'The moonstone', + author: 'Wilkie Collins', + language: 'Italian', + image: './images/the_moonstone.jpg', + }, + little_women: { + title: 'Little women', + author: 'Louisa May Alcott', + language: 'French', + image: './images/little_women.jpg', + }, + three_men_in_boat: { + title: 'Three men in a boat', + author: 'Jerome K Jerome', + language: 'English', + image: './images/three_men_in_boat.jpg', + }, + the_sign_of_four: { + title: 'The sign of four', + author: 'Arthur Conan Doyle', + language: 'French', + image: './images/the_sign_of_four.jpg', + }, + new_grub_street: { + title: 'New grub street', + author: 'George Gissing', + language: 'English', + image: './images/new_grub_street.jpg', + }, + jude_the_obscure: { + title: 'Jude the obscure', + author: 'Thomas Hardy', + language: 'Dutch ', + image: './images/jude_the_obscure.jpg', + }, + heart_of_darkness: { + title: 'Heart of darkness', + author: 'Joseph Conrad', + language: 'Turkish', + image: './images/heart_of_darkness.jpg', + }, + sister_carrie: { + title: 'Sister carrie', + author: 'Theodore Dreiser', + language: 'English', + image: './images/sister_carrie.jpg', + }, + the_rainbow: { + title: 'The rainbow', + author: 'DH Lawrence', + language: 'Spanish', + image: './images/the_rainbow.jpg', + }, + }; + // Replace with your own code - console.log(bookTitles); + function book_data() { + const book_ul = document.createElement('ul'); + + for (let i in bookTitles) { + const book_li = document.createElement('li'); + const book_title = document.createElement('h1'); + const book_author = document.createElement('p'); + const book_language = document.createElement('p'); + const book_cover = document.createElement('img'); + book_title.innerHTML = bookData[bookTitles[i]].title; + book_author.innerHTML = bookData[bookTitles[i]].author; + book_language.innerHTML = bookData[bookTitles[i]].language; + book_cover.src = bookData[bookTitles[i]].image; + book_li.appendChild(book_cover); + book_li.appendChild(book_title); + book_li.appendChild(book_author); + book_li.appendChild(book_language); + book_ul.appendChild(book_li); + } + document.body.appendChild(book_ul); + } + + book_data(); } diff --git a/Week1/homework/images/brave_new_world.jpg b/Week1/homework/images/brave_new_world.jpg new file mode 100644 index 000000000..e32998e80 Binary files /dev/null and b/Week1/homework/images/brave_new_world.jpg differ diff --git a/Week1/homework/images/heart_of_darkness.jpg b/Week1/homework/images/heart_of_darkness.jpg new file mode 100644 index 000000000..10f5d8f93 Binary files /dev/null and b/Week1/homework/images/heart_of_darkness.jpg differ diff --git a/Week1/homework/images/jude_the_obscure.jpg b/Week1/homework/images/jude_the_obscure.jpg new file mode 100644 index 000000000..e90c6e0cc Binary files /dev/null and b/Week1/homework/images/jude_the_obscure.jpg differ diff --git a/Week1/homework/images/little_women.jpg b/Week1/homework/images/little_women.jpg new file mode 100644 index 000000000..cffc42a00 Binary files /dev/null and b/Week1/homework/images/little_women.jpg differ diff --git a/Week1/homework/images/new_grub_street.jpg b/Week1/homework/images/new_grub_street.jpg new file mode 100644 index 000000000..75f3f5c7f Binary files /dev/null and b/Week1/homework/images/new_grub_street.jpg differ diff --git a/Week1/homework/images/sister_carrie.jpg b/Week1/homework/images/sister_carrie.jpg new file mode 100644 index 000000000..93265853e Binary files /dev/null and b/Week1/homework/images/sister_carrie.jpg differ diff --git a/Week1/homework/images/the_moonstone.jpg b/Week1/homework/images/the_moonstone.jpg new file mode 100644 index 000000000..6ba36f30b Binary files /dev/null and b/Week1/homework/images/the_moonstone.jpg differ diff --git a/Week1/homework/images/the_rainbow.jpg b/Week1/homework/images/the_rainbow.jpg new file mode 100644 index 000000000..36a78b010 Binary files /dev/null and b/Week1/homework/images/the_rainbow.jpg differ diff --git a/Week1/homework/images/the_sign_of_four.jpg b/Week1/homework/images/the_sign_of_four.jpg new file mode 100644 index 000000000..73bbd75b4 Binary files /dev/null and b/Week1/homework/images/the_sign_of_four.jpg differ diff --git a/Week1/homework/images/three_men_in_boat.jpg b/Week1/homework/images/three_men_in_boat.jpg new file mode 100644 index 000000000..b29ade9a8 Binary files /dev/null and b/Week1/homework/images/three_men_in_boat.jpg differ diff --git a/Week1/homework/index.html b/Week1/homework/index.html index b22147cd1..3d827503c 100644 --- a/Week1/homework/index.html +++ b/Week1/homework/index.html @@ -1 +1,14 @@ - \ No newline at end of file + + +
+ + + + + +