diff --git a/Week-1/Homework/mandatory/1-writers.js b/Week-1/Homework/mandatory/1-writers.js index 82acf6f..5871b94 100644 --- a/Week-1/Homework/mandatory/1-writers.js +++ b/Week-1/Homework/mandatory/1-writers.js @@ -38,6 +38,9 @@ let writers = [ alive: true } ]; +for(let i = 0; i < writers.length; i+=1){ + console.log(`Hi, my name is ${writers[i].firstName} ${writers[i].lastName}. I am ${writers[i].age} years old, and work as a ${writers[i].occupation}.`) +} /* If you want an extra challenge, only `console.log()` the writers that are alive. diff --git a/Week-1/Homework/mandatory/2-water-bottle.js b/Week-1/Homework/mandatory/2-water-bottle.js index 981d7e3..d972892 100644 --- a/Week-1/Homework/mandatory/2-water-bottle.js +++ b/Week-1/Homework/mandatory/2-water-bottle.js @@ -11,13 +11,16 @@ We made a start on this for you here: let bottle = { volume: 0, fill: function() { - // calling this function should make you bottles volume = 100; + this.volume = 100;// calling this function should make you bottles volume = 100; }, drink: function() { - // calling this function should decrease your bottles volume by 10; + this.volume -= 10;// calling this function should decrease your bottles volume by 10; }, empty: function() { - // this function should return true if your bottles volume = 0 + if ( this.volume === 0) { + return true; + } + return false;// this function should return true if your bottles volume = 0 } }; diff --git a/Week-1/Homework/mandatory/3-groceries.js b/Week-1/Homework/mandatory/3-groceries.js index 2b34cdb..f6dcd85 100644 --- a/Week-1/Homework/mandatory/3-groceries.js +++ b/Week-1/Homework/mandatory/3-groceries.js @@ -6,7 +6,11 @@ let groceriesToBuy = []; let groceryList = { - item1: "", - item2: "", - item3: "" + item1: "Potatoes", + item2: "Orange Juice", + item3: "Rice" }; +for(let key in groceryList) { + groceriesToBuy.push(groceryList[key]) +} +console.log(groceriesToBuy); diff --git a/Week-1/Homework/projects/1-recipes.js b/Week-1/Homework/projects/1-recipes.js index 3ada67c..ebe1bfe 100644 --- a/Week-1/Homework/projects/1-recipes.js +++ b/Week-1/Homework/projects/1-recipes.js @@ -22,4 +22,9 @@ cocoa **/ -let recipes = {}; +let recipes = { + title: "Mole", + numberOfServings: 2, + ingredients: ["cinnamon", "cumin", "cocoa"] +}; +console.log(recipes.title); \ No newline at end of file diff --git a/Week-1/Homework/projects/2-reading-list.js b/Week-1/Homework/projects/2-reading-list.js index 939e3e2..062ff69 100644 --- a/Week-1/Homework/projects/2-reading-list.js +++ b/Week-1/Homework/projects/2-reading-list.js @@ -25,4 +25,28 @@ If you read it, log a string like 'You already read "The Hobbit" by J.R.R. Tolki **/ -let books = []; +let books = [ + { + title: "the Hobbit", + author: "J.R.R. Tolkien", + alreadyRead: true + }, + { + title: "Harry Potter", + author: "Rowling", + alreadyRead: true + }, + { + title: "Lord of the Flies", + author: "Golding", + alreadyRead: true + } +]; + +books.forEach(function(book) { + if (books.alreadyRead) + console.log("You ara already read " + book.title + " by " + book.author); + else { + console.log("You still need to read " + book.title + " by " + book.author); + } +}); diff --git a/Week-1/InClass/A-objects-intro/exercise-part-0.js b/Week-1/InClass/A-objects-intro/exercise-part-0.js index 433d27c..55c2df8 100644 --- a/Week-1/InClass/A-objects-intro/exercise-part-0.js +++ b/Week-1/InClass/A-objects-intro/exercise-part-0.js @@ -4,4 +4,10 @@ Describe your own laptop as a JavaScript object Try to think of as many properties as you can! -*/ \ No newline at end of file +*/ +let laptpp = { + model:"Dell", + thchScreen: false, + memmory: "3gb" +} +console.log(laptop) \ No newline at end of file diff --git a/Week-1/InClass/A-objects-intro/exercise-part-1.js b/Week-1/InClass/A-objects-intro/exercise-part-1.js index 49e1ed9..22a2ecb 100644 --- a/Week-1/InClass/A-objects-intro/exercise-part-1.js +++ b/Week-1/InClass/A-objects-intro/exercise-part-1.js @@ -7,3 +7,36 @@ Assign each of them to a separate variable */ +let cat = { + coulor: "red", + name: "Shenko", + age: "3years" +} + +let house = { + rooms: 3, + bathrooms: 1, + kitchen: 1, + garden: 1, + balcouny: false +} + +let car = { + typeOfCar: "Toyota", + year:2017, + numberOfDoors: 5 +} + +let shopingList = { + item1 : "Milk", + item2 : "Hony", + item3 : "Bread", + item4 : "Potato" +} + +let countriesILivedIn = { + cont1: "UK", + cont2: "Sudan", + cont3: "Qatar", + cont4: "Saudi Arabia" +} \ No newline at end of file diff --git a/Week-1/InClass/A-objects-intro/exercise-part-2.js b/Week-1/InClass/A-objects-intro/exercise-part-2.js index 4e01403..3bd6afe 100644 --- a/Week-1/InClass/A-objects-intro/exercise-part-2.js +++ b/Week-1/InClass/A-objects-intro/exercise-part-2.js @@ -5,17 +5,18 @@ The objects below have some syntax issues - try and fix them all! */ let kitten = { - fur colour: "orange", - age "23" + furcolour: "orange", + age: "23" }; -let laptop = - brand: "Lenovo" - ram "5GB" +let laptop = { + brand: "Lenovo", + ram: "5GB" } let phone = { - operating system "iOS", + operatingsystem: "iOS", hasStylus: true, - megapixels 12 - "batteryLife": "24 hours" \ No newline at end of file + megapixels: 12, + batteryLife: "24 hours" +} \ No newline at end of file diff --git a/Week-1/InClass/B-objects-get-set/exercise-1.js b/Week-1/InClass/B-objects-get-set/exercise-1.js index 6591384..6c4a26a 100644 --- a/Week-1/InClass/B-objects-get-set/exercise-1.js +++ b/Week-1/InClass/B-objects-get-set/exercise-1.js @@ -11,7 +11,8 @@ let kitten = { // YOUR CODE GOES BELOW HERE - +let x = kitten.ageMonths; +console.log(x); diff --git a/Week-1/InClass/B-objects-get-set/exercise-2.js b/Week-1/InClass/B-objects-get-set/exercise-2.js index c8b5e7b..bdec015 100644 --- a/Week-1/InClass/B-objects-get-set/exercise-2.js +++ b/Week-1/InClass/B-objects-get-set/exercise-2.js @@ -5,14 +5,14 @@ */ let phone = { - brand: 'iPhone, - model 'iPhone X' + brand: 'iPhone', + model: 'iPhone X', launchYear: 2017, - is Unlocked: true -; + isUnlocked: true +} -let phoneBrand = phone.bbrand; -let phoneLaunchYear = phone[launchYear]; +let phoneBrand = phone.brand; +let phoneLaunchYear = phone.launchYear; // DO NOT MODIFY BELOW THIS LINE diff --git a/Week-1/InClass/B-objects-get-set/exercise-3.js b/Week-1/InClass/B-objects-get-set/exercise-3.js index f775c9a..65dd114 100644 --- a/Week-1/InClass/B-objects-get-set/exercise-3.js +++ b/Week-1/InClass/B-objects-get-set/exercise-3.js @@ -3,7 +3,10 @@ */ // WRITE CODE BELOW THIS - +let kitten = { + name: "Gilbert", + age: 3 +} // WRITE CODE ABOVE THIS console.log(kitten.name); diff --git a/Week-1/InClass/B-objects-get-set/exercise-4.js b/Week-1/InClass/B-objects-get-set/exercise-4.js index 763347e..75bc9c3 100644 --- a/Week-1/InClass/B-objects-get-set/exercise-4.js +++ b/Week-1/InClass/B-objects-get-set/exercise-4.js @@ -9,7 +9,8 @@ let dog = { // WRITE CODE BELOW THIS LINE - +dog.name = "Rex"; +dog.wantsToPlay = true; // WRITE CODE ABOVE THIS LINE diff --git a/Week-1/InClass/C-more-complex-objects/exercise-1.js b/Week-1/InClass/C-more-complex-objects/exercise-1.js index 8ae3e82..dce7c95 100644 --- a/Week-1/InClass/C-more-complex-objects/exercise-1.js +++ b/Week-1/InClass/C-more-complex-objects/exercise-1.js @@ -18,6 +18,10 @@ let house = { WRITE YOUR CODE BELOW */ +house.address = '51 Berkley Road'; +house.previousOwners = ["Brian M.", "Fiona S."]; +house.currentOwner.lastName = "Montgomery"; +console.log(house); // - change the address of "house" to '51 Berkley Road' // - change the previous owners of "house" to ["Brian M.", "Fiona S."] diff --git a/Week-1/InClass/C-more-complex-objects/exercise-2.js b/Week-1/InClass/C-more-complex-objects/exercise-2.js index 7ea0200..df0d353 100644 --- a/Week-1/InClass/C-more-complex-objects/exercise-2.js +++ b/Week-1/InClass/C-more-complex-objects/exercise-2.js @@ -24,6 +24,9 @@ let newCurrentOwner = { WRITE YOUR CODE BELOW */ +house.currentOwner = newCurrentOwner +house.previousOwners[1] = " Stephen B." +house.isForSale = false // - assign the value of the variable 'newCurrentOwner' as the value to the house's "currentOwner" // - from the list of previous owners, replace only "John A." with "Stephen B." diff --git a/Week-1/InClass/C-more-complex-objects/exercise-3.js b/Week-1/InClass/C-more-complex-objects/exercise-3.js index 4bfbfd3..79fcc8a 100644 --- a/Week-1/InClass/C-more-complex-objects/exercise-3.js +++ b/Week-1/InClass/C-more-complex-objects/exercise-3.js @@ -32,17 +32,17 @@ let parkAvenueHouse = { // returns the full name (first name + last name) of the owner of the house function getOwnerFullName(house) { - + return `${house.currentOwner.firstName} ${house.currentOwner.lastName}` } // returns an array of the owners' email addresses of the two houses function getEmailAddresses(house1, house2) { - + return `${house1.currentOwner.email} , ${house2.currentOwner.email}` } // returns the address for the cheapest house out of the two function getCheapestAddress(house1, house2) { - + return house1.price > house2.price } diff --git a/Week-1/InClass/D-methods/exercise-1.js b/Week-1/InClass/D-methods/exercise-1.js index 8de0f8c..6150611 100644 --- a/Week-1/InClass/D-methods/exercise-1.js +++ b/Week-1/InClass/D-methods/exercise-1.js @@ -6,7 +6,10 @@ Add a method "greet" so this person can say hello. let person = { name: "Alice", - age: 25 + age: 25, + greet(){ + return "Hello everybody" + } }; diff --git a/Week-1/InClass/D-methods/exercise-2.js b/Week-1/InClass/D-methods/exercise-2.js index 8e993fc..e593b54 100644 --- a/Week-1/InClass/D-methods/exercise-2.js +++ b/Week-1/InClass/D-methods/exercise-2.js @@ -7,7 +7,10 @@ Hint: use 'this' keyword to access the name property. let person = { name: "Alice", - age: 25 + age: 25, + sayName: function () { + return "My name is " + this.name + } }; diff --git a/Week-1/InClass/D-methods/exercise-3.js b/Week-1/InClass/D-methods/exercise-3.js index be23748..109f9d8 100644 --- a/Week-1/InClass/D-methods/exercise-3.js +++ b/Week-1/InClass/D-methods/exercise-3.js @@ -8,11 +8,11 @@ let person = { name: "Alice", age: 25, currentAddress: "Glasgow", - changeAddress: (newAddress) { - currentAddress = newAddress; + changeAddress: function(newAddress) { + this.currentAddress = newAddress; }, - celebrateBirthday: function { - that.age = that.age + 1; + celebrateBirthday: function() { + this.age = this.age + 1; } }; diff --git a/Week-1/InClass/D-methods/exercise-4.js b/Week-1/InClass/D-methods/exercise-4.js index d89214a..dc597a3 100644 --- a/Week-1/InClass/D-methods/exercise-4.js +++ b/Week-1/InClass/D-methods/exercise-4.js @@ -6,7 +6,10 @@ Define a method "makeFriend" to add a new friend to her list. let person = { name: "Alice", - friends: ["John", "Nina"] + friends: ["John", "Nina"], + makeFriend(newFriend) { + this.friends.push(newFriend) + } }; diff --git a/Week-1/InClass/D-methods/exercise-5.js b/Week-1/InClass/D-methods/exercise-5.js index dcd198c..e1c59dd 100644 --- a/Week-1/InClass/D-methods/exercise-5.js +++ b/Week-1/InClass/D-methods/exercise-5.js @@ -17,9 +17,24 @@ let coffeeMachine = { }, insertedAmount: 0, insertMoney: function (amount) { + return this.insertedAmount = amount; + if (amount >= 1.50 && amount < 2.40) { + return this.insertedAmount; + }else if (amount >=2.40 && amount <3.00) { + return this.insertedAmount; + }else { + return this.insertedAmount; + } }, getCoffee: function (coffee) { + if (this.insertedAmount >= 1.50 && this.insertedAmount < 2.40) { + return `Please take your ${coffee}`; + }else if (this.insertedAmount >= 2.40 && this.insertedAmount < 3.00) { + return `Plaase take your ${coffee}`; + }else { + return `Please take your ${coffee}` + } } }; diff --git a/Week-1/InClass/E-arrays-of-objects/exercise-1.js b/Week-1/InClass/E-arrays-of-objects/exercise-1.js index 8d39a81..3e3939b 100644 --- a/Week-1/InClass/E-arrays-of-objects/exercise-1.js +++ b/Week-1/InClass/E-arrays-of-objects/exercise-1.js @@ -25,11 +25,11 @@ WRITE YOUR CODE BELOW */ -var persons = // Complete here +var persons = [person1, person2, person3]// Complete here -var personNames = // Complete here +var personNames = persons.map(x => x.name) // Complete here -var personsYoungerThan28YearsOld = // Complete here +var personsYoungerThan28YearsOld = persons.filter(x => x.age < 28) // Complete here /* diff --git a/Week-1/InClass/E-arrays-of-objects/exercise-2.js b/Week-1/InClass/E-arrays-of-objects/exercise-2.js index c2259dd..c5e59ee 100644 --- a/Week-1/InClass/E-arrays-of-objects/exercise-2.js +++ b/Week-1/InClass/E-arrays-of-objects/exercise-2.js @@ -40,11 +40,11 @@ WRITE YOUR CODE BELOW */ -let destinationNamesWithin500Kms = // Complete here +let destinationNamesWithin500Kms = travelDestinations.filter(a => a.distanceKms < 500).map(b => b.destinationName);// Complete here -let destinationNameReachableByFerry = // Complete here +let destinationNameReachableByFerry = travelDestinations.find(c => c.transportations.includes(`ferry`)).destinationName;// Complete here -let destinationNamesMoreThan300KmsAwayByTrain = // Complete here (PRINT THE RESULT IN THE CONSOLE USING FOREACH) +let destinationNamesMoreThan300KmsAwayByTrain = travelDestinations.filter(a => a.distanceKms > 300).filter(c => c.transportations.includes(`train`)).map(a => a.destinationName);// Complete here (PRINT THE RESULT IN THE CONSOLE USING FOREACH) /* diff --git a/Week-1/InClass/E-arrays-of-objects/exercise-3.js b/Week-1/InClass/E-arrays-of-objects/exercise-3.js index a1ec691..3b8b5f6 100644 --- a/Week-1/InClass/E-arrays-of-objects/exercise-3.js +++ b/Week-1/InClass/E-arrays-of-objects/exercise-3.js @@ -60,13 +60,13 @@ let restaurantFinderApplication = { applicationVersion: "1.0", restaurants: restaurants, findAvailableRestaurants: function (numberOfPeople) { - // Complete here + return this.restaurants.filter(x => x.totalSeats - x.numberOfCustomers >= numberOfPeople).map(x => x.name);// Complete here }, findRestaurantServingDish: function (dishName) { - // Complete here + return this.restaurants.filter(x => x.menu.includes(dishName)).map(x => x.name); // Complete here }, countNumberOfRestaurantsInArea: function (area) { - // Complete here + return this.restaurants.filter(x => x.address.area === area).length;// Complete here } }; diff --git a/Week-1/InClass/F-object-keys/exercise-part-0.js b/Week-1/InClass/F-object-keys/exercise-part-0.js index d9b1085..2588f93 100644 --- a/Week-1/InClass/F-object-keys/exercise-part-0.js +++ b/Week-1/InClass/F-object-keys/exercise-part-0.js @@ -20,8 +20,8 @@ let highScores = { // ONLY EDIT BELOW HERE -let capitalCitiesKeys = ; -let highScoresKeys; +let capitalCitiesKeys = Object.keys(capitalCities); +let highScoresKeys = Object.keys(highScores); // ONLY EDIT ABOVE HERE diff --git a/Week-1/InClass/F-object-keys/exercise-part-1.js b/Week-1/InClass/F-object-keys/exercise-part-1.js index b8d4be7..1656f10 100644 --- a/Week-1/InClass/F-object-keys/exercise-part-1.js +++ b/Week-1/InClass/F-object-keys/exercise-part-1.js @@ -15,9 +15,9 @@ let mentorsAges = { // ONLY EDIT BELOW THIS LINE -let mentorsNames = ; +let mentorsNames = Object.keys(mentorsAges); -let mentorsNamedUppercased = ; +let mentorsNamedUppercased = mentorsNames.map(x=>x.toUpperCase()); // ONLY EDIT ABOVE THIS LINE diff --git a/Week-2/Homework/mandatory/2-exercises/exercises.js b/Week-2/Homework/mandatory/2-exercises/exercises.js index 174c5db..702259c 100644 --- a/Week-2/Homework/mandatory/2-exercises/exercises.js +++ b/Week-2/Homework/mandatory/2-exercises/exercises.js @@ -15,8 +15,17 @@ */ function exerciseOne(arrayOfPeople) { let content = document.querySelector("#content"); + for (let i = 0; i < arrayOfPeople.length; i++) { + let namesEl = document.createElement("h1"); + let jopEl = document.createElement("h2"); + content.appendChild(namesEl); + content.appendChild(jopEl); + namesEl.innerHTML= arrayOfPeople[i].name; + jopEl.innerHTML = arrayOfPeople[i].job; + } } + /** * * Create a list of shopping items. You should use an unordered list. @@ -25,9 +34,15 @@ function exerciseOne(arrayOfPeople) { * */ function exerciseTwo(shopping) { - //Write your code in here + let content = document.querySelector("#content"); + let ul = document.createElement("ul"); + for (let i = 0; i < shopping.length; i++){ + let li = document.createElement("li") + ul.textContent = shopping[i]; + ul.appendChild(li) //Write your code in here +} +content.appendChild(ul); } - /** I'd like to display my three favorite books inside a nice webpage! @@ -58,7 +73,36 @@ function exerciseTwo(shopping) { The end result should look something like this: https://hyf-js2-week1-makeme-ex1-demo.herokuapp.com/ **/ function exerciseThree(books) { - //Write your code in here + let content = document.querySelector("#content"); + let ul = document.createElement("ul"); + let imge = [ + 'www.bookicious.com/books/design-of-everyday-things.gif' + , + 'https://www.kurzweilai.net/images/The-Most-Human-Human-Paperback-Front-Cover.jpg', + + 'https://upload.wikimedia.org/wikipedia/en/8/8f/The_pragmatic_programmer.jpg' + + ]; + for (let i = 0; i < books.length; i++) { + let p = document.createElement("p"); + let li = document.createElement("li"); + let img = document.createElement("img"); + let title = books[i].title; + let author = books[i].author; + let alreadyRead = books[i].alreadyRead; + p.textContent = `${title}, ${author}, ${alreadyRead}`; + img.src = imge[i]; + img.style.wedth = "250px"; + if (alreadyRead === true) { + li.style.backgroundColor = "green"; + }else { + li.style.backgroundColor = "red"; + } + li.appendChild(p); + li.appendChild(img); + ul.appendChild(li); + } + contect.appendChild(ul); //Write your code in here } // diff --git a/Week-2/InClass/A-dom-manipulation/exercise.js b/Week-2/InClass/A-dom-manipulation/exercise.js index bb4f2e9..faade18 100644 --- a/Week-2/InClass/A-dom-manipulation/exercise.js +++ b/Week-2/InClass/A-dom-manipulation/exercise.js @@ -5,6 +5,7 @@ Write JavaScript below that logs: 1. all the "p" element nodes of the document, --> should log a list of nodes with a length of 6 + 2. the first div element node --> should log the ".site-header" node @@ -15,6 +16,18 @@ Write JavaScript below that logs: --> should log a list of nodes with a length of 3 */ +//(1) +console.log(document.querySelectorAll("p")); + +//(2) +console.log(document.querySelector("div")); + +//(3) +console.log(document.queryCommandValue("#jumbotron-text")); + +//(4) +arrEl = Array.from(document.querySelectorAll(".primary-content p")); +console.log(arrEl); /* @@ -24,7 +37,10 @@ Task 2 When a user clicks the 'ALERT' button, an alert box should pop up with the text "Thanks for visiting Bikes for Refugees!" */ - +var alertCl = document.querySelector("#alertbtn"); +alertCl.addEventListener("click", function() { + alert("Thanks for visiting Bikes for Refugees!"); +}) /* Task 3 ======= @@ -32,6 +48,10 @@ Task 3 Write JavaScript below that changes the background colour of the page when the 'Change colour' button is clicked. */ +var changeBcCol = document.querySelector("#bgrChangeBtn"); +changeBcCol.addEventListener("click", function() { + document.body.style.backgroundColor = "yellow"; +}) /* Task 4 @@ -39,6 +59,12 @@ Task 4 When a user clicks the 'Add some text' button, a new paragraph should be added below the buttons that says "Read more below." */ +var newTextbtn = document.querySelector("#addTextBtn"); +var p = document.createElement("p"); +p.textContent = "Read more below."; +newTextbtn.addEventListener("click", function(){ + newTextbtn.parentNode.appendChild(p); +}) @@ -47,4 +73,8 @@ Task 5 ====== When the 'Larger links!' button is clicked, the text of all links on the page should increase. -*/ \ No newline at end of file +*/ +// var largLink = document.querySelector("#largerLinksBtn"); +// largLink.addEventListener("click", function(){ +// largLink.style.fontSize("18px") +// }) \ No newline at end of file diff --git a/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js b/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js index 6ca81cd..4ac023f 100644 --- a/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js +++ b/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js @@ -1,5 +1,25 @@ -function setAlarm() {} +function setAlarm() { + let stopBtn = document.getElementById("stop"); +let setBtn = document.getElementById("set"); + let display = document.getElementById("timeRemaining"); + let inputNum = document.getElementById("alarmSet"); + inputNum = inputNum.value; + + let interval = setInterval (function(){ + if(inputNum >= 0) { + + display.textContent = `Time Remaining: 0${inputNum}:00` + inputNum--; + }else{ + playAlarm(); + } + }, 1000); + stopBtn.addEventListener("click", function(){ + clearInterval(interval); +}); + +} // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); diff --git a/Week-3/Homework/mandatory/1-alarmclock/index.html b/Week-3/Homework/mandatory/1-alarmclock/index.html index ab7d582..6db1570 100644 --- a/Week-3/Homework/mandatory/1-alarmclock/index.html +++ b/Week-3/Homework/mandatory/1-alarmclock/index.html @@ -2,7 +2,6 @@ Alarm Clock - Time Remaining: 00:00 + diff --git a/Week-3/Homework/mandatory/1-alarmclock/style.css b/Week-3/Homework/mandatory/1-alarmclock/style.css index 0c72de3..e1f5409 100644 --- a/Week-3/Homework/mandatory/1-alarmclock/style.css +++ b/Week-3/Homework/mandatory/1-alarmclock/style.css @@ -1,13 +1,17 @@ + .centre { position: fixed; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); + background-color: aqua; + text-align: center; } #alarmSet { margin: 20px; + text-align: left; } h1 { diff --git a/Week-3/Homework/mandatory/2-quotegenerator/index.html b/Week-3/Homework/mandatory/2-quotegenerator/index.html index b6115be..9daf845 100644 --- a/Week-3/Homework/mandatory/2-quotegenerator/index.html +++ b/Week-3/Homework/mandatory/2-quotegenerator/index.html @@ -2,7 +2,7 @@ Quote Generator - + +
+ +
+ + diff --git a/Week-3/Homework/mandatory/2-quotegenerator/quotes.js b/Week-3/Homework/mandatory/2-quotegenerator/quotes.js index 39ab245..26c8120 100644 --- a/Week-3/Homework/mandatory/2-quotegenerator/quotes.js +++ b/Week-3/Homework/mandatory/2-quotegenerator/quotes.js @@ -1,3 +1,14 @@ +let newBtn = document.querySelector("button"); + +newBtn.addEventListener("click", function() { + let authorOut = document.getElementById("authorOut"); + let quoteOutpu = document.getElementById("quoteOutput"); + let randomQuo =pickFromArray(quotes); + quoteOutpu.innerHTML = randomQuo.quote; + authorOut.innerHTML = randomQuo.author; +}) + + // DO NOT EDIT BELOW HERE // A function which will return one item, at diff --git a/Week-3/Homework/mandatory/3-slideshow/image/1.jpeg b/Week-3/Homework/mandatory/3-slideshow/image/1.jpeg new file mode 100644 index 0000000..d3c65db Binary files /dev/null and b/Week-3/Homework/mandatory/3-slideshow/image/1.jpeg differ diff --git a/Week-3/Homework/mandatory/3-slideshow/image/2.jpg b/Week-3/Homework/mandatory/3-slideshow/image/2.jpg new file mode 100644 index 0000000..0b3be44 Binary files /dev/null and b/Week-3/Homework/mandatory/3-slideshow/image/2.jpg differ diff --git a/Week-3/Homework/mandatory/3-slideshow/image/3.jpg b/Week-3/Homework/mandatory/3-slideshow/image/3.jpg new file mode 100644 index 0000000..dba9bec Binary files /dev/null and b/Week-3/Homework/mandatory/3-slideshow/image/3.jpg differ diff --git a/Week-3/Homework/mandatory/3-slideshow/image/4.jpg b/Week-3/Homework/mandatory/3-slideshow/image/4.jpg new file mode 100644 index 0000000..6bdbca8 Binary files /dev/null and b/Week-3/Homework/mandatory/3-slideshow/image/4.jpg differ diff --git a/Week-3/Homework/mandatory/3-slideshow/image/5.jpg b/Week-3/Homework/mandatory/3-slideshow/image/5.jpg new file mode 100644 index 0000000..dfb536a Binary files /dev/null and b/Week-3/Homework/mandatory/3-slideshow/image/5.jpg differ diff --git a/Week-3/Homework/mandatory/3-slideshow/image/6.png b/Week-3/Homework/mandatory/3-slideshow/image/6.png new file mode 100644 index 0000000..e86a540 Binary files /dev/null and b/Week-3/Homework/mandatory/3-slideshow/image/6.png differ diff --git a/Week-3/Homework/mandatory/3-slideshow/index.html b/Week-3/Homework/mandatory/3-slideshow/index.html index 39cd40e..f134ca4 100644 --- a/Week-3/Homework/mandatory/3-slideshow/index.html +++ b/Week-3/Homework/mandatory/3-slideshow/index.html @@ -2,7 +2,7 @@ Slideshow - + + +
+
Back ward
+
Previous
+
Stop
+
Next
+
For ward
+
+ + + + diff --git a/Week-3/Homework/mandatory/3-slideshow/slideshow.js b/Week-3/Homework/mandatory/3-slideshow/slideshow.js index b55091c..9233293 100644 --- a/Week-3/Homework/mandatory/3-slideshow/slideshow.js +++ b/Week-3/Homework/mandatory/3-slideshow/slideshow.js @@ -1 +1,64 @@ // Write your code here +// Write your code here +let imgArray = ["image/1.jpeg", "image/2.jpg", "image/3.jpg", "image/4.jpg", "image/5.jpg", "image/6.png"]; +let prevBtn = document.querySelector("#previousBtn"); +let nextBtn = document.querySelector("#nextBtn"); +let forwardBtn = document.querySelector("#forkWard"); +let staopBtn = document.querySelector("#stopBtn"); +let backwardBtn = document.querySelector("#backWard"); +let stopRunForward; +let stopRunBackward; + + +let counter = 0; +let backCounter = imgArray.length - 1; + +nextBtn.addEventListener("click", function() { + if (counter > imgArray.length - 2) { + counter = -1; + } + counter++; + let image = document.querySelector("img"); + image.src= imgArray[counter]; + counter = backCounter; + console.log(counter); +}); + +prevBtn.addEventListener("click", function(){ + if (backCounter <= 0) { + backCounter = imgArray.length -1; + } + backCounter--; + let image = document.querySelector("img"); + image.src = imgArray[backCounter]; + console.log(backCounter); +}); +forwardBtn.addEventListener("click", function () { + clearInterval(stopRunBackward); + stopRunForward = setInterval(function () { + if (counter > imageArray.length - 2) { + counter = -1; + } + counter++; + let image = document.querySelector("img"); + image.src = imageArray[counter]; + backCounter = counter; + console.log(counter); + }, 1000); + }); + backwardBtn.addEventListener("click", function () { + clearInterval(stopRunForward); + stopRunBackward = setInterval(function () { + if (backCounter <= 0) { + backCounter = imageArray.length; + } + backCounter--; + let image = document.querySelector("img"); + image.src = imageArray[backCounter]; + console.log(backCounter); + }, 1000); + }); + stopBtn.addEventListener("click", function () { + clearInterval(stopRunForward); + clearInterval(stopRunBackward); + }); \ No newline at end of file diff --git a/Week-3/Homework/mandatory/3-slideshow/style.css b/Week-3/Homework/mandatory/3-slideshow/style.css index 63cedf2..d5d869f 100644 --- a/Week-3/Homework/mandatory/3-slideshow/style.css +++ b/Week-3/Homework/mandatory/3-slideshow/style.css @@ -1 +1,37 @@ /** Write your CSS in here **/ +* { + padding: 0; + margin: 0; + block-size: border-box; + } + + .carousel-container { + width: 50%; + margin: auto; + border: 10px solid black; + } + img { + width: 700px; + height: 500px; + background-color: aquamarine; + } + .buttons { + display: flex; + justify-content: center; + } + + #backWard { + margin: 40px; + } + #previousBtn { + margin: 40px; + } + #stopBtn { + margin: 40px; + } + #nextBtn { + margin: 40px; + } + #forkWard { + margin: 40px; + } \ No newline at end of file