From b8057133be020b12775cef6209b9a7c036ea35a8 Mon Sep 17 00:00:00 2001 From: Nour Saeed Date: Fri, 9 Aug 2019 22:02:00 +0200 Subject: [PATCH] add --- Week1/homework/app.js | 125 ++++++++++++++++++++++++++++++++++--- Week1/homework/index.html | 19 +++++- Week2/example.html | 3 +- Week2/lecture-exercises.js | 36 ++++++++++- 4 files changed, 172 insertions(+), 11 deletions(-) diff --git a/Week1/homework/app.js b/Week1/homework/app.js index a9b5f75d8..f607f7e80 100644 --- a/Week1/homework/app.js +++ b/Week1/homework/app.js @@ -1,11 +1,122 @@ -'use strict'; +'use strict'; { - const bookTitles = [ - // Replace with your own book titles - 'harry_potter_chamber_secrets', - ]; - // Replace with your own code - console.log(bookTitles); + const title = [ + + 'harry_potter_chamber_secrets', + + 'alchemist', //Paulo coelho + 'paula', + 'orlando', + 'divine-comedy', + 'the-odyssey', + ]; + + let objBooks = { + + "harry_potter_chamber_secrets" : + { + + title :"harry_potter_chamber_secrets", + + language:"english", + + author:"Joanne K. Rowling", + + }, + + "alchemist": + { + title:"alchemist", + + language:"english", + + author:"paulo-coelho", + + }, + + "paula":{ + + title:"paula", + + language:"english", + + author:"isabel allende", + + }, + "orlando": + { + title:"orlando", + + language:"english", + + author:"virgina wolf", + + }, + "divine-comedy" : + { + + title:"divine-comedy", + + language:"English", + + author:"dante", + + }, + + "the-odyssey": + { + + title:"the-odyssey", + + language: "english", + + author:"homeros", + + } + + + + } + + + + function listBooks() { + + let i = 0; + + let ul = document.createElement('ul') + + for (i = 0; i < title.length; i++) { + + let li = document.createElement('li'); + + li.textContent = title[i]; + + ul.appendChild(li); + } + } + + document.body.appendChild(ul); + document.body.onload = listBooks; + const objBooksArr = []; + for (const newListBooks in objBooks) { + console.log(newListBooks); + objBooksArr.push(objBooks[newListBooks]) + } + + + +const bookPic = { + + 'harry_potter_chamber_secrets':potter.jpg , + 'alchemist':alchemist, + 'paula' :paula.jpg, + 'orlando':woolf.jpg, + 'divine-comedy':divine.jpg, + 'the-odyssey' :odyssy.jpg, +}; + + diff --git a/Week1/homework/index.html b/Week1/homework/index.html index b22147cd1..f86ac5162 100644 --- a/Week1/homework/index.html +++ b/Week1/homework/index.html @@ -1 +1,18 @@ - \ No newline at end of file + + + + + + + + Book Titles + + + + + +
+ + + + diff --git a/Week2/example.html b/Week2/example.html index 374f064c4..0d0d7e4eb 100644 --- a/Week2/example.html +++ b/Week2/example.html @@ -14,7 +14,8 @@

Here is your advice for the day:

-

+ + diff --git a/Week2/lecture-exercises.js b/Week2/lecture-exercises.js index 1fdfef4e0..68d136493 100644 --- a/Week2/lecture-exercises.js +++ b/Week2/lecture-exercises.js @@ -9,9 +9,41 @@ async function getRandomAdvice() { return adviceData.slip.advice; } +let allAdvice=[] +const adviceEl = document.getElementById('advice'); + + +function updateDOM() { + adviceEl.innerHTML= ''; + + allAdvice.forEach((advice, index)=> { + + + const adviceItem=document.createElement ('li') + adviceEl.appendChild(adviceItem); + adviceItem.innerText=advice; + + const removeButton =document.createElement('button') + removeButton.innerText='remove'; + adviceItem.appendChild(removeButton); + removeButton.addEventListener('click',() => deleteAdvice(index));_ +}) + } + function deleteAdvice (index){ + allAdvice.splice(index,1); + updateDOM(); + } + function upcaseAllAdvice (){ + allAdvice=allAdvice.map(advice => advice.toUpperCase()); + updateDOM(); + async function setRandomAdvice() { - const adviceEl = document.getElementById('advice'); - adviceEl.innerText = await getRandomAdvice(); + allAdvice.push (await getRandomAdvice()); + updateDOM(); } setRandomAdvice(); + +document.getElementById('add-advice').addEventListener('click', setRandomAdvice); + +document.getElementById('upcase-everything').addEventListener('click', upcaseAllAdvice); \ No newline at end of file