diff --git a/InClass/Callbacks/exercise-1/exercise.js b/InClass/Callbacks/exercise-1/exercise.js index d74ca9d..c4b3cb0 100644 --- a/InClass/Callbacks/exercise-1/exercise.js +++ b/InClass/Callbacks/exercise-1/exercise.js @@ -11,3 +11,20 @@ Update your code to make the colour change every 5 seconds to something differen Prefer to work on a codepen? https://codepen.io/makanti/pen/abOreLg ================ */ + +//Answer to task 1 +// setTimeout(function(){ +// let colorBase = "#a2"; +// let randomIndex = Math.floor(Math.random() * 10); +// document.body.style.backgroundColor = colorBase + randomIndex; +// console.log(randomIndex); +// }, 5000); + +//Answer to task 2 +function changeColor(){ + let colorBase = "#a2"; + let randomIndex = Math.floor(Math.random() * 10); + document.body.style.backgroundColor = colorBase + randomIndex; + console.log(randomIndex); +} +setInterval(changeColor, 5000); \ No newline at end of file diff --git a/InClass/Callbacks/exercise-2/exercise.js b/InClass/Callbacks/exercise-2/exercise.js index 6d362da..cac4605 100644 --- a/InClass/Callbacks/exercise-2/exercise.js +++ b/InClass/Callbacks/exercise-2/exercise.js @@ -34,6 +34,8 @@ TIP: Use the functions you created on tasks 1-3 Prefer to work on a codepen? https://codepen.io/makanti/pen/MWwMgmW?editors ================ */ + + const movies = [ { title: "Color Out of Space", @@ -61,8 +63,66 @@ const movies = [ }, ]; -// create showMovies function +let allMovies = document.getElementById("all-movies"); +let movieNumbers = document.getElementById("movies-number"); + +//Answer to Task 1 +function showMovies(array){ + + //Iterating through the given array to create a p tag and it's content for each object in the array: + array.forEach(movie => { + let details = document.createElement("p"); + details.innerHTML = `

${movie.title}

\n

${movie.director}

\n `; + allMovies.append(details); + }) + + //Displaying the number of the movies + movieNumbers.innerText = array.length; +} + +//Answer to Task 2 +function addMovie(object){ + setTimeout(movies.push(object), 2000); +} + +//Answer to Task 3 +// let newMovie = { +// title: "Beautiful Day in the Neighborhood", +// director: "Marielle Heller", +// type: "drama", +// haveWatched : true +// } +// addMovie(newMovie); + + +//Answer to Task 4 +function createObject(){ + + //Creating and asigning variables to form values: + let newTitle, movieDirector, movieType, watchedOrNot, watchedOrNotArray, checked; + newTitle = document.getElementById("title").value; + movieDirector = document.getElementById("director").value; + movieType = document.getElementById("type").value; + watchedOrNot = document.getElementsByName("hasWatched"); + watchedOrNotArray = Array.from(watchedOrNot); + checked = watchedOrNotArray.find(option => option.checked); + + //Creating the new movie object + let newMovie = { + title: newTitle, + director: movieDirector, + type: movieType, + hasWatched: Boolean(checked.value) + } + + //Adding the new movie object to the list of arrays called "movies" using the addMovie helper function: + addMovie(newMovie) +} + +//form add movie button +let addBtn = document.getElementById("addBtn"); -// create a new movie object for your favorite movie +//Listening for when the button is clicked +addBtn.addEventListener("click", createObject); -// create addMovies function +setTimeout(showMovies(movies), 5000); \ No newline at end of file diff --git a/InClass/Callbacks/exercise-2/index.html b/InClass/Callbacks/exercise-2/index.html index bc9654c..45bc95d 100644 --- a/InClass/Callbacks/exercise-2/index.html +++ b/InClass/Callbacks/exercise-2/index.html @@ -23,6 +23,19 @@

My movies

Number of movies:

+
+
+
 
+
+
 
+
+
 
+ + + + >
 
+ +
diff --git a/InClass/DOM-practice/main.js b/InClass/DOM-practice/main.js index be9f609..67bdf68 100644 --- a/InClass/DOM-practice/main.js +++ b/InClass/DOM-practice/main.js @@ -4,7 +4,13 @@ console.log("Testing JS file loaded!") // Without changing any of the HTML or CSS, update the
tags so that they have white backgrounds. +//Answer: +//Accession the section tag +let sections = document.getElementsByTagName("section"); +let sectionsArray = Array.from(sections); +//Changing each section background to white(#ffffff) +sectionsArray.forEach(section => section.style.backgroundColor = "#ffffff") @@ -14,6 +20,13 @@ console.log("Testing JS file loaded!") // Without changing any of the HTML or CSS, update the images on the page so that they are all centered. // Hint: look at the CSS to see if there are any classes already written which you can use. +let images = document.getElementsByTagName("img"); +let imagesArray = Array.from(images); +imagesArray.forEach(image => { + image.style.marginLeft = "auto"; + image.style.marginRight = "auto"; + image.style.display = "block"; +}) @@ -23,3 +36,15 @@ console.log("Testing JS file loaded!") // 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
. +let sectionParagraphs = document.querySelectorAll("section p"); +let sectionParagraphsArray = Array.from(sectionParagraphs); +let graceHopperDOB = "9 December 1906"; +let graceHopperDOD = "1 January 1992"; +let katJohnsonDOB = "26 August 1918"; +let katJohnsonDOD = "24 February 2020"; +let adaLovelaceDOB = "10 December 1815"; +let adaLovelaceDOD = "27 November 1852"; + +sectionParagraphsArray[2].innerHTML += `Date of Birth: ${graceHopperDOB}\tDate of Death: ${graceHopperDOD}`; +sectionParagraphsArray[4].innerHTML += `Date of Birth: ${katJohnsonDOB}\tDate of Death: ${katJohnsonDOD}`; +sectionParagraphsArray[8].innerHTML += `Date of Birth: ${adaLovelaceDOB}\tDate of Death: ${adaLovelaceDOD}`; \ No newline at end of file diff --git a/mandatory/1-alarmclock/alarmclock.js b/mandatory/1-alarmclock/alarmclock.js index 6ca81cd..3b1e062 100644 --- a/mandatory/1-alarmclock/alarmclock.js +++ b/mandatory/1-alarmclock/alarmclock.js @@ -1,4 +1,68 @@ -function setAlarm() {} +//Declaring variables +let setAlarmBtn, stopAlarmBtn, pauseAlarmBtn, input, counter; + +//Assigning ids to variables +setAlarmBtn = document.getElementById("set"); +stopAlarmBtn = document.getElementById("stop"); +pauseAlarmBtn = document.getElementById("pause"); +input = document.getElementById("alarmSet"); +counter = document.getElementById("timeRemaining"); + +//Start alarm function +function setAlarm() { + let hours, minutes; + if(input.value >= 60){ + hours = Math.floor(input.value / 60); + minutes = input.value - hours * 60; + if(minutes < 10){ + counter.innerText = `Time Remaining: ${hours}:0${minutes}` + } else { + counter.innerText = `Time Remaining: ${hours}:${minutes}` + } + } else { + minutes = input.value + if(minutes < 10){ + counter.innerText = `Time Remaining: 00:0${minutes}`; + } else { + counter.innerText = `Time Remaining: 00:${minutes}`; + } + } + if(input.value > 0){ + input.value--; + } else { + playAlarm(); + setInterval(changeColor, 1000); + document.body.style.backgroundColor = "#ffffff"; + } +} + +//This function handles the countdown +let countDown= function() { + setInterval(setAlarm, 1000); +} + +//This function sets the background colour to red when it is called +function changeColor(){ + document.body.style.backgroundColor = "red"; +} + +//This function sets the background colour to white when it is called +function plainBackground(){ + document.body.style.backgroundColor = "#ffffff"; +} + +//Listening for events +setAlarmBtn.addEventListener("click", countDown); +stopAlarmBtn.addEventListener("click", function(){ + clearInterval(countDown); +}); +pauseAlarmBtn.addEventListener("click", function(){ + setInterval(function(){ + input.value++; + }, 1000); + +}); + // DO NOT EDIT BELOW HERE diff --git a/mandatory/1-alarmclock/index.html b/mandatory/1-alarmclock/index.html index 2bc9beb..4f420a9 100644 --- a/mandatory/1-alarmclock/index.html +++ b/mandatory/1-alarmclock/index.html @@ -22,6 +22,7 @@

Time Remaining: 00:00

+
diff --git a/mandatory/2-quotegenerator/index.html b/mandatory/2-quotegenerator/index.html index 0d5c549..ffc74c8 100644 --- a/mandatory/2-quotegenerator/index.html +++ b/mandatory/2-quotegenerator/index.html @@ -11,7 +11,11 @@ - +
+

CLICK THE BUTTON

+ +
+
diff --git a/mandatory/2-quotegenerator/quotes.js b/mandatory/2-quotegenerator/quotes.js index 39ab245..19093e9 100644 --- a/mandatory/2-quotegenerator/quotes.js +++ b/mandatory/2-quotegenerator/quotes.js @@ -1,3 +1,11 @@ +let quoteP = document.getElementById("quote"); +let newQuoteBtn = document.getElementById("newQuoteBtn"); +function showQuote(quoteFromArray){ + quoteP.innerHTML = `${quoteFromArray.quote}
-${quoteFromArray.author}`; +} + + + // DO NOT EDIT BELOW HERE // A function which will return one item, at @@ -21,6 +29,7 @@ function pickFromArray(choices) { return choices[Math.floor(Math.random() * choices.length)]; } + // A list of quotes you can use in your app. // Feel free to edit them, and to add your own favourites. const quotes = [ @@ -490,3 +499,7 @@ const quotes = [ author: "Zig Ziglar", }, ]; + +newQuoteBtn.addEventListener("click", function(){ + showQuote(pickFromArray(quotes)); +}) diff --git a/mandatory/2-quotegenerator/style.css b/mandatory/2-quotegenerator/style.css index 63cedf2..3f886a3 100644 --- a/mandatory/2-quotegenerator/style.css +++ b/mandatory/2-quotegenerator/style.css @@ -1 +1,51 @@ -/** Write your CSS in here **/ +body{ + background-color: #40e0d0; + display:flex; + justify-content: center; +} +.quote-container{ + display:flex; + flex-direction:column; + align-items:center; + justify-content:center; + background-color:#ffffff; + width:70vw; + height:70vh; +} + +.quote-container p{ + font-size:2rem; + padding:6rem; +} + +.newQuoteBtn{ + width:200px; + height:100px; + padding:1rem; + border-radius:10px; + font-size:1.5rem; + box-shadow:5px 10px; + + border:10px solid #21CCBB; + font-weight:bold; + background-color:#ffffff; +} + +.newQuoteBtn:hover{ + background-color: #21CCBB; + border-color:#ffffff; + transition: all .5s linear; +} + +/* Design */ +.circle1{ + width:1000px; + height:1000px; + border-radius:50%; + background-color:#21CCBB; + position:fixed; + top:400px; + left:-200px; + z-index:-100; +} + diff --git a/mandatory/3-slideshow/img/camera.jpg b/mandatory/3-slideshow/img/camera.jpg new file mode 100644 index 0000000..8e88fa1 Binary files /dev/null and b/mandatory/3-slideshow/img/camera.jpg differ diff --git a/mandatory/3-slideshow/img/earpods.jpg b/mandatory/3-slideshow/img/earpods.jpg new file mode 100644 index 0000000..9353228 Binary files /dev/null and b/mandatory/3-slideshow/img/earpods.jpg differ diff --git a/mandatory/3-slideshow/img/gameboy.jpg b/mandatory/3-slideshow/img/gameboy.jpg new file mode 100644 index 0000000..4463661 Binary files /dev/null and b/mandatory/3-slideshow/img/gameboy.jpg differ diff --git a/mandatory/3-slideshow/img/studySet.jpg b/mandatory/3-slideshow/img/studySet.jpg new file mode 100644 index 0000000..e5b1bbe Binary files /dev/null and b/mandatory/3-slideshow/img/studySet.jpg differ diff --git a/mandatory/3-slideshow/index.html b/mandatory/3-slideshow/index.html index 68c163c..e9ef3cc 100644 --- a/mandatory/3-slideshow/index.html +++ b/mandatory/3-slideshow/index.html @@ -9,9 +9,36 @@ crossorigin="anonymous" /> + - - +
+
+ A camera +
+
+ Earpods +
+
+ A gameboy +
+
+ Study set +
+
+
+ +
+
+ +
+
+ + + +
+ + + diff --git a/mandatory/3-slideshow/slideshow.js b/mandatory/3-slideshow/slideshow.js index b55091c..8670b25 100644 --- a/mandatory/3-slideshow/slideshow.js +++ b/mandatory/3-slideshow/slideshow.js @@ -1 +1,57 @@ -// Write your code here +let slider = document.getElementById("slider"); +let images = document.querySelectorAll(".image img"); +let imagesArray = Array.from(images); +let forwardBtn = document.getElementById("fowardBtnContainer"); +let backwardBtn = document.getElementById("backwardBtnContainer"); +let autoBackBtn = document.getElementById("autoBackBtn"); +let autoFrontBtn = document.getElementById("autoFrontBtn"); +let stopBtn = document.getElementById("stopBtn"); + + let translateUnits = 0; +let addUnits = 1950; + +function slideForward(){ + translateUnits += addUnits; + if(translateUnits >= 5900){ + translateUnits = 0; + } else { + translateUnits = translateUnits; + } + + slider.style.transform = `translate(-${translateUnits}px)`; + slider.style.transition = "transform 1s linear"; + +} + +function slideBackward(){ + translateUnits -= addUnits; + if(translateUnits <= -1950){ + translateUnits = 5850; + } else { + translateUnits = translateUnits; + } + slider.style.transform = `translate(-${translateUnits}px)`; + slider.style.transition = "transform 1s linear"; + console.log(translateUnits); +} + +let autoForward = function(){ + setInterval(slideForward, 1500); +} + +let autoBackward = function(){ + setInterval(slideBackward, 1500); +} + + +forwardBtn.addEventListener("click", slideForward); +backwardBtn.addEventListener("click", slideBackward); +autoBackBtn.addEventListener("click", function(){ + if(autoForward){ + clearInterval(autoForward); + autoBackward(); + } else { + autoBackward(); + } +}); +autoFrontBtn.addEventListener("click", autoForward); diff --git a/mandatory/3-slideshow/style.css b/mandatory/3-slideshow/style.css index 63cedf2..e11c30a 100644 --- a/mandatory/3-slideshow/style.css +++ b/mandatory/3-slideshow/style.css @@ -1 +1,53 @@ -/** Write your CSS in here **/ +.slider{ + position:fixed; + display:flex; + z-index:0; +} + + +.image-container { + padding:150px 0px 150px 650px; + width:77vw; + height:97vh; + background-color:white; +} + + +.image-container img{ + width:auto; + height:800px; +} + +.lastImage{ + padding-right:670px; +} + +/*Left and right Controls*/ +.fowardBtnContainer i{ + font-size:3em; + position:fixed; + right:100px; + top:500px; +} +.backwardBtnContainer i { + font-size: 3em; + position: fixed; + left: 100px; + top: 500px; +} + +/* auto controls*/ +.buttons{ + position:fixed; + top:1000px; + left:900px; +} + +.btn{ + padding:1rem 2rem; + margin-left:1rem; + font-size:2.5rem; + border-radius:30px; + background-color:pink; +} +