diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..973492c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "cSpell.words": [ + "Corneliu", + "Porumboiu", + "Whannell", + "codepen" + ] +} \ No newline at end of file diff --git a/InClass/Callbacks/exercise-1/exercise.js b/InClass/Callbacks/exercise-1/exercise.js index 40f06b0..d17c2e2 100644 --- a/InClass/Callbacks/exercise-1/exercise.js +++ b/InClass/Callbacks/exercise-1/exercise.js @@ -5,9 +5,53 @@ EXERCISE 1 Task 1 Using setTimeout, change the background colour of the page after 5 seconds (5000 milliseconds). + Task 2 Update your code to make the colour change every 5 seconds to something different. Hint: try searching for setInterval. Complete the exercises in this CodePen Prefer to work on a codepen? https://codepen.io/makanti/pen/abOreLg ================ -*/ \ No newline at end of file +*/ + +// Exercise 1 -Syllabus +const greekGods = [ + "Aphrodite", + "Ares", + "Artemis", + "Athena", + "Poseidon", + "Zeus", +]; + +// before running the code in your browser, discuss the expected order of each loop + +// synchronous - loop through the array of greek gods and print the index numbers and values to the console, e.g. '1. Ares' +greekGods.forEach((item, i) => console.log(i, item)); +// asynchronous - same as before but the index and the value of the god at position 2 in array should be printed after 2 seconds. Use: setTimeout() +greekGods.forEach((element, i) => { + setTimeout(() => { + if (i === 2) { + console.log(i, element); + } + }, 2000); + if (i === 2) { + return; + } + console.log(i, element); +}); + +const body = document.querySelector("body"); +// Task 1 +setTimeout(() => { + body.style.backgroundColor = "blue"; +}, 5000); + +// Task 2 +let colours = ["red", "blue", "green", "purple"]; + +let change = 0; +setInterval(() => { + if (change === colours.length) change = 0; + body.style.backgroundColor = colours[change]; + change++; +}, 5000); diff --git a/InClass/Callbacks/exercise-2/exercise.js b/InClass/Callbacks/exercise-2/exercise.js index eca9595..2e8725c 100644 --- a/InClass/Callbacks/exercise-2/exercise.js +++ b/InClass/Callbacks/exercise-2/exercise.js @@ -63,8 +63,35 @@ const movies = [ // create showMovies function +const contentDiv = document.getElementById("all-movies"); +const spanEl = document.getElementById("movies-number"); + +const showMovies = (movie) => { + movie.forEach((item) => { + let pTag = document.createElement("p"); + contentDiv.appendChild(pTag); + pTag.innerHTML = `${item.title} - ${item.director}`; + spanEl.innerHTML = `${movies.length}`; + }); +}; +showMovies(movies); // create a new movie object for your favorite movie +const newMovie = { + title: "47 Ronin", + director: "Carl Rinsch", + type: "action", + haveWatched: true, +}; + // create addMovies function + +const addMovie = (movie) => { + setTimeout(() => { + movie.push(newMovie); + showMovies(movies.slice(-1)); + }, 2000); +}; +addMovie(movies); diff --git a/InClass/Callbacks/exercise-2/index.html b/InClass/Callbacks/exercise-2/index.html index bc9654c..7e45ce2 100644 --- a/InClass/Callbacks/exercise-2/index.html +++ b/InClass/Callbacks/exercise-2/index.html @@ -24,6 +24,7 @@

My movies

+ \ No newline at end of file diff --git a/InClass/DOM-practice/index.html b/InClass/DOM-practice/index.html index 9c78866..e3ecb4b 100644 --- a/InClass/DOM-practice/index.html +++ b/InClass/DOM-practice/index.html @@ -27,7 +27,7 @@

The Mothers of Computing

-
+
Grace Hopper

Grace Hopper

@@ -59,7 +59,7 @@

Grace Hopper


-
+
Katherine Johnson @@ -110,7 +110,7 @@

Katherine Johnson


-
+
Ada Lovelace @@ -154,7 +154,7 @@

Ada Lovelace

-

Made with <3 by Bex

+

Made with 3 by Bex

diff --git a/InClass/DOM-practice/main.js b/InClass/DOM-practice/main.js index be9f609..4379590 100644 --- a/InClass/DOM-practice/main.js +++ b/InClass/DOM-practice/main.js @@ -1,25 +1,40 @@ -console.log("Testing JS file loaded!") +console.log("Testing JS file loaded!"); // Task 1 // Without changing any of the HTML or CSS, update the
tags so that they have white backgrounds. - - - - +const changeSectionColor = (colour) => { + let sectionTag = document.querySelectorAll("section"); + sectionTag.forEach((item) => (item.style.backgroundColor = colour)); +}; +changeSectionColor("white"); // Task 2 // Without changing any of the HTML or CSS, update the images on the page so that they are all centered. - +const centerImages = () => { + let imgCenter = document.querySelectorAll("img"); + imgCenter.forEach((element) => { + element.classList.add("content-title"); + }); +}; +centerImages(); // Hint: look at the CSS to see if there are any classes already written which you can use. - - - - - // Task 3 // Google the date of birth and death of each of the people on the page. Without changing any of the HTML or CSS, add this in a paragraph to the end of their
. + +const grace = document.getElementById("grace"); +const katherine = document.getElementById("katherine"); +const ada = document.getElementById("ada"); +const pTag1 = document.createElement("p"); +const pTag2 = document.createElement("p"); +const pTag3 = document.createElement("p"); +pTag1.innerText = 'DOB: 9 December 1906' + ', ' + 'Died: 1 January 1992'; +grace.appendChild(pTag1); +pTag2.innerText = "DOB: 26 August 1918" + ", " + "Died: 24 February 2020"; +katherine.appendChild(pTag2); +pTag3.innerText = "DOB: 10 December 1815" + ", " + "Died: 27 November 1852"; +ada.appendChild(pTag3); \ No newline at end of file diff --git a/mandatory/1-alarmclock/alarmclock.js b/mandatory/1-alarmclock/alarmclock.js index 6ca81cd..239d3d7 100644 --- a/mandatory/1-alarmclock/alarmclock.js +++ b/mandatory/1-alarmclock/alarmclock.js @@ -1,4 +1,21 @@ -function setAlarm() {} +let timerInterval = null; +const inputTime = document.getElementById("alarmSet"); +const timeRemain = document.getElementById("timeRemaining"); + +const setAlarm = () => { + let timeCountDown = inputTime.value; + timeRemain.innerHTML = `Time Remaining: 00:${inputTime.value}`; + let timerInterval = setInterval(() => { + timeRemain.innerHTML = `Time Remaining: 00:${timeCountDown}`; + if (timeCountDown > 0) { + timeCountDown -= 1; + } + if (timeCountDown === 0) { + clearInterval(timerInterval); + playAlarm(); + } + }, 1000); +}; // DO NOT EDIT BELOW HERE diff --git a/mandatory/1-alarmclock/index.html b/mandatory/1-alarmclock/index.html index ab7d582..2a2ddbc 100644 --- a/mandatory/1-alarmclock/index.html +++ b/mandatory/1-alarmclock/index.html @@ -2,7 +2,7 @@ Alarm Clock - + Time Remaining: 00:00 + diff --git a/mandatory/2-quotegenerator/index.html b/mandatory/2-quotegenerator/index.html index b6115be..dfee763 100644 --- a/mandatory/2-quotegenerator/index.html +++ b/mandatory/2-quotegenerator/index.html @@ -2,7 +2,7 @@ Quote Generator - + +
+

Quotes Generator of Famous People

+ +
+

quote

+
+

author

+
+ diff --git a/mandatory/2-quotegenerator/quotes.js b/mandatory/2-quotegenerator/quotes.js index 39ab245..8231c43 100644 --- a/mandatory/2-quotegenerator/quotes.js +++ b/mandatory/2-quotegenerator/quotes.js @@ -490,3 +490,18 @@ const quotes = [ author: "Zig Ziglar", }, ]; + +const quote = document.getElementById('quote'); +const quoteAuthor = document.getElementById('quoteAuthor'); +const quoteBtn = document.querySelector('#quoteBtn'); + + +const displayQuote = () => { + let random = Math.floor(Math.random() * quotes.length); + quoteAuthor.innerHTML = `${quotes[random].author}`; + quote.innerHTML = `${quotes[random].quote}`; +} + +quoteBtn.addEventListener("click", displayQuote); + +window.onload = displayQuote(); \ No newline at end of file diff --git a/mandatory/2-quotegenerator/style.css b/mandatory/2-quotegenerator/style.css index 63cedf2..6438722 100644 --- a/mandatory/2-quotegenerator/style.css +++ b/mandatory/2-quotegenerator/style.css @@ -1 +1,46 @@ /** Write your CSS in here **/ +body { + min-height: 100vh; + display: flex; + justify-content: center; + align-items: center; + background-color: aqua; + color: #333; + font-family: 'Calibri', sans-serif; + font-weight: 400; + text-transform: capitalize; +} + +.container { + text-align: center; + padding: 2rem; + border-radius: 5px; + background-color: #fff; + flex: 0 0 80%; +} + +#quoteBtn { + border: none; + color: #fff; + background: #753b08; + padding: 0.25rem 0.5rem; + border-radius: 7px; + font-size: 1.3rem; + cursor: pointer; + outline: none; +} + +#quoteBtn:hover { + color: #ffd000; +} + +blockquote { + border-left: 10px solid #753b08; + margin: 1.5rem; + padding: 0.5rem; + background-color: #f9f9f9; +} + +#quoteAuthor { + color: #ffd000; +} \ No newline at end of file diff --git a/mandatory/3-slideshow/img/bg-0.jpg b/mandatory/3-slideshow/img/bg-0.jpg new file mode 100644 index 0000000..2960dad Binary files /dev/null and b/mandatory/3-slideshow/img/bg-0.jpg differ diff --git a/mandatory/3-slideshow/img/bg-1.jpg b/mandatory/3-slideshow/img/bg-1.jpg new file mode 100644 index 0000000..b1d6071 Binary files /dev/null and b/mandatory/3-slideshow/img/bg-1.jpg differ diff --git a/mandatory/3-slideshow/img/bg-2.jpg b/mandatory/3-slideshow/img/bg-2.jpg new file mode 100644 index 0000000..8b196dd Binary files /dev/null and b/mandatory/3-slideshow/img/bg-2.jpg differ diff --git a/mandatory/3-slideshow/img/bg-3.jpg b/mandatory/3-slideshow/img/bg-3.jpg new file mode 100644 index 0000000..6318e99 Binary files /dev/null and b/mandatory/3-slideshow/img/bg-3.jpg differ diff --git a/mandatory/3-slideshow/img/bg-4.jpg b/mandatory/3-slideshow/img/bg-4.jpg new file mode 100644 index 0000000..7cc2ff0 Binary files /dev/null and b/mandatory/3-slideshow/img/bg-4.jpg differ diff --git a/mandatory/3-slideshow/img/bg-5.jpg b/mandatory/3-slideshow/img/bg-5.jpg new file mode 100644 index 0000000..6f6809a Binary files /dev/null and b/mandatory/3-slideshow/img/bg-5.jpg differ diff --git a/mandatory/3-slideshow/img/bg-6.jpg b/mandatory/3-slideshow/img/bg-6.jpg new file mode 100644 index 0000000..0174f89 Binary files /dev/null and b/mandatory/3-slideshow/img/bg-6.jpg differ diff --git a/mandatory/3-slideshow/img/bg-7.jpg b/mandatory/3-slideshow/img/bg-7.jpg new file mode 100644 index 0000000..92a8433 Binary files /dev/null and b/mandatory/3-slideshow/img/bg-7.jpg differ diff --git a/mandatory/3-slideshow/img/bg-8.jpg b/mandatory/3-slideshow/img/bg-8.jpg new file mode 100644 index 0000000..7378d9e Binary files /dev/null and b/mandatory/3-slideshow/img/bg-8.jpg differ diff --git a/mandatory/3-slideshow/img/bg-9.jpg b/mandatory/3-slideshow/img/bg-9.jpg new file mode 100644 index 0000000..b2fb2c8 Binary files /dev/null and b/mandatory/3-slideshow/img/bg-9.jpg differ diff --git a/mandatory/3-slideshow/index.html b/mandatory/3-slideshow/index.html index 39cd40e..20dd9d4 100644 --- a/mandatory/3-slideshow/index.html +++ b/mandatory/3-slideshow/index.html @@ -2,7 +2,7 @@ Slideshow - + + + +
+ + + + + + + +
+ + + + diff --git a/mandatory/3-slideshow/slideshow.js b/mandatory/3-slideshow/slideshow.js index b55091c..319d705 100644 --- a/mandatory/3-slideshow/slideshow.js +++ b/mandatory/3-slideshow/slideshow.js @@ -1 +1,80 @@ // Write your code here +const imgContainer = document.querySelector('.images'); +const autoBackBtn = document.querySelector('.auto-backBtn'); +const backBtn = document.querySelector('.backBtn'); +const stopBtn = document.querySelector('.stopBtn'); +const forwardBtn = document.querySelector('.forwardBtn'); +const autoForwardBtn = document.querySelector('.auto-forwardBtn'); + +let count = 0; + +// Slideshow manual forward +const forwardSlide = () => { + imgContainer.animate([{opacity: '0.1'}, {opacity: '1.0'}], {duration: 1000, fill: 'forwards'}) + if(count === 10) { + count = -1; + } + count++; + + imgContainer.style.backgroundImage = `url(/mandatory/3-slideshow/img/bg-${count}.jpg`; +} + +// Slideshow manual back +const backSlide = () => { + imgContainer.animate([{opacity: '0.1'}, {opacity: '1.0'}], {duration: 1000, fill: 'forwards'}) + if (count === 0) { + count = 11; + } + count--; + + imgContainer.style.backgroundImage = `url(/mandatory/3-slideshow/img/bg-${count}.jpg`; +} + +// Auto forward slideshow +let slideIndex = 0; +let stopSlide; + +const forwardSlideShow = () => { + clearInterval(stopSlide); + imgContainer.animate([{opacity: '0.1'}, {opacity: '1.0'}], {duration: 1000, fill: 'forwards'}) + for(let i = 0; i < imgContainer.length; i++) { + imgContainer[i].style.display = 'none'; + } + + if(slideIndex === 9) { + slideIndex = -1; + } + slideIndex++; + imgContainer.style.backgroundImage = `url(/mandatory/3-slideshow/img/bg-${slideIndex}.jpg`; + stopSlide = setInterval(forwardSlideShow, 2000); +} + +// Auto back slideshow + +const backSlideShow = () => { + clearInterval(stopSlide) + imgContainer.animate([{opacity: '0.1'}, {opacity: '1.0'}], {duration: 1000, fill: 'forwards'}) + for(let i = 0; i < imgContainer.length; i++) { + imgContainer[i].style.display = 'none'; + } + + if(slideIndex === 0) { + slideIndex = 10; + } + slideIndex--; + imgContainer.style.backgroundImage = `url(/mandatory/3-slideshow/img/bg-${slideIndex}.jpg`; + stopSlide = setTimeout(backSlideShow, 2000); +} + +// Stop slideshow + +const stopSlideShow = () => { + clearInterval(stopSlide); +} + +// EventListeners = buttons +backBtn.addEventListener('click', backSlide); +forwardBtn.addEventListener('click', forwardSlide); +autoForwardBtn.addEventListener('click', forwardSlideShow); +autoBackBtn.addEventListener('click', backSlideShow); +stopBtn.addEventListener('click', stopSlideShow); \ No newline at end of file diff --git a/mandatory/3-slideshow/style.css b/mandatory/3-slideshow/style.css index 63cedf2..626f362 100644 --- a/mandatory/3-slideshow/style.css +++ b/mandatory/3-slideshow/style.css @@ -1 +1,67 @@ /** Write your CSS in here **/ +body { + min-height: 100vh; + display: flex; + justify-content: center; + align-items: center; + background: coral; +} + +.images { + flex: 0 0 80%; + min-height: 70vh; + background: url('/mandatory/3-slideshow/img/bg-0.jpg')center /cover no-repeat; + border-radius: 15px; + box-sizing: 5px 10px black; + position: relative; +} + +.btn { + display: inline-block; + background: #fff; + border: 3px solid green; + font-size: 1.5rem; + padding: 0.5rem; + border-radius: 20%; + box-shadow: 2px 5px black; + outline: none; +} + +.auto-backBtn { + position: absolute; + bottom: 0; +} + +.backBtn { + position: absolute; + bottom: 0; + left: 131px; +} + +.stopBtn { + position: absolute; + bottom: 0; + left: 204px; +} + +.forwardBtn { + position: absolute; + bottom: 0; + left: 276px; +} + +.auto-forwardBtn { + position: absolute; + bottom: 0; + left: 385px; +} + +.btn:active { + background: grey; + box-shadow: 1px 1px grey; +} + +.btn:hover { + background: chartreuse; + color: rgb(197, 52, 8); +} \ No newline at end of file