diff --git a/InClass/Callbacks/exercise-1/exercise.js b/InClass/Callbacks/exercise-1/exercise.js index 40f06b0..b9fc937 100644 --- a/InClass/Callbacks/exercise-1/exercise.js +++ b/InClass/Callbacks/exercise-1/exercise.js @@ -10,4 +10,34 @@ 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 ================ -*/ \ No newline at end of file +*/ + +/* + * Task 1 + */ +let mainDiv = document.getElementById("main"); +let task1Complete = false; +setTimeout(() => { + mainDiv.style.backgroundColor = "red"; + task1Complete = true; + console.log("in timeout"); + console.log("task 1 status" + task1Complete); + }, 5000); + + +/* + * Task 2 + */ +function task2() { + let colorList = [ "yellow", "blue", "green", "#efefef", "#0ae071"]; + let count = 0; + + if(task1Complete) { + setInterval(() => { + mainDiv.style.backgroundColor = colorList[count]; + count = (count + 1) % colorList.length; + }, 1000) + } +} + +setTimeout(task2, 7000); diff --git a/InClass/Callbacks/exercise-2/exercise.js b/InClass/Callbacks/exercise-2/exercise.js index eca9595..72b8b8e 100644 --- a/InClass/Callbacks/exercise-2/exercise.js +++ b/InClass/Callbacks/exercise-2/exercise.js @@ -13,13 +13,13 @@ Create a function called "showMovies" that Task 2 Amend your function above to only show movies after 1 second. Remember to use setTimeout to achieve that Create a new function called "addMovie" -- it receives a movie object as an argument - your can create a new object for your favorite movie following using the "myMovies" objects as a guide +- it receives a movie object as an argument - your can create a new object for your favorite movie following using the "myMovies" objects as a guide - it adds the new movie to the list of movies after 2 seconds. Remember to setTimeout to achieve that Call addMovies to add the new movie to the list and then showMovies to see the movies added on the screen. How many movies can you see on your page? Task 3 -Can you make sure the new movie you just added is showing on the screen? +Can you make sure the new movie you just added is showing on the screen? TIP: use callbacks Task 4 - **Extra** @@ -61,10 +61,71 @@ const movies = [ }, ]; +let moviesDisplayed = 0; + // create showMovies function +function showMovies() { + let allMovies = document.getElementById("all-movies"); + let moviesNumber = document.getElementById("movies-number"); + // show movies after 1s + setTimeout(() => { + // add the number of movies to the moviesNumber + moviesNumber.innerText = movies.length; -// create a new movie object for your favorite movie + // display movies on the page + for(let i = moviesDisplayed; i < movies.length; i++) { + let para = document.createElement("p"); + para.innerText = movies[i].title + " - " + movies[i].director; + allMovies.appendChild(para); + moviesDisplayed++; + } + }, 1000); +} + +showMovies(); +// create a new movie object for your favorite movie +const myFavMovie = { + title: "Inception", + director: "Christopher Nolan", + type: "sci-fi", + haveWatched: true, +} // create addMovies function +function addMovie(movie) { + // add this new movie to the movies array + setTimeout(() => { + movies.push(movie); + }, 1000); +} + +addMovie(myFavMovie); +setTimeout(showMovies, 2100); + +// task 4 +function task4() { + + let submitbtn = document.getElementById("submitBtn"); + + submitbtn.addEventListener("click", event => { + + event.preventDefault(); + + let moveTitle = document.getElementById("movieTitle"); + let movieDirector = document.getElementById("movieDirector"); + let movieGenre = document.getElementById("movieGenre"); + let movieWatched = document.getElementById("movieWatched"); + let newMovie = { + title: moveTitle.value, + director: movieDirector.value, + type: movieGenre.value, + haveWatched: movieWatched.value, + }; + addMovie(newMovie); + setTimeout(showMovies, 2100); + }); +} + +task4(); diff --git a/InClass/Callbacks/exercise-2/index.html b/InClass/Callbacks/exercise-2/index.html index bc9654c..dc04175 100644 --- a/InClass/Callbacks/exercise-2/index.html +++ b/InClass/Callbacks/exercise-2/index.html @@ -16,6 +16,7 @@ +

My movies

@@ -23,7 +24,44 @@

My movies

Number of movies:

- - +
+

Tell us your favourite movie!

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

The Mothers of Computing

-
+
Grace Hopper -

Grace Hopper

+

Grace Hopper

Called the Queen of Software by some and Grandma COBOL by others, Navy @@ -59,12 +59,12 @@

Grace Hopper


-
+
Katherine Johnson -

Katherine Johnson

+

Katherine Johnson

Being handpicked to be one of three black students to integrate West @@ -110,12 +110,12 @@

Katherine Johnson


-
+
Ada Lovelace -

Ada Lovelace

+

Ada Lovelace

Ada Lovelace was unique in that she developed an algorithm for a diff --git a/InClass/DOM-practice/main.js b/InClass/DOM-practice/main.js index be9f609..5b2ce48 100644 --- a/InClass/DOM-practice/main.js +++ b/InClass/DOM-practice/main.js @@ -4,9 +4,14 @@ console.log("Testing JS file loaded!") // Without changing any of the HTML or CSS, update the

tags so that they have white backgrounds. +function task1() { + let sections = document.getElementsByTagName("section"); + for(let i = 0; i < sections.length; i++) { + sections[i].style.backgroundColor = "#ffffff"; + } +} - - +task1(); // Task 2 @@ -15,11 +20,53 @@ console.log("Testing JS file loaded!") // Hint: look at the CSS to see if there are any classes already written which you can use. +function task2() { + let imgs = document.getElementsByTagName("img"); + for(let i = 0; i < imgs.length; i++) { + imgs[i].className += " content-title"; + } +} - - +task2(); // 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 dates = [ + { + person: "grace-hopper", + birth: "9 December 1906", + death: "1 January 1992" + }, + { + person: "katherine-johnson", + birth: "26 August 1918", + death: "24 February 2020" + }, + { + person: "ada-lovelace", + birth: "10 December 1815", + death: "27 November 1852" + } +]; + +function task3() { + let sections = document.getElementsByTagName("section"); + + for(let i = 0; i < sections.length; i++) { + let newPara = document.createElement("p"); + + birth = dates.filter( value => + value.person === sections[i].id).map(value => value.birth); + + death = dates.filter( value => + value.person === sections[i].id).map(value => value.death); + + newPara.innerText = `Born: ${birth}. Died: ${death}`; + sections[i].appendChild(newPara); + } +} + +task3(); \ No newline at end of file diff --git a/mandatory/1-alarmclock/alarmclock.js b/mandatory/1-alarmclock/alarmclock.js index 6ca81cd..ee077c6 100644 --- a/mandatory/1-alarmclock/alarmclock.js +++ b/mandatory/1-alarmclock/alarmclock.js @@ -1,4 +1,35 @@ -function setAlarm() {} +let isAlarmSet = false; + +function setBtnEventListener() { + let heading = document.getElementById("timeRemaining"); + let timer; + let input = document.getElementById("alarmSet"); + if(input.value !== "" && !isAlarmSet) { + console.log("Alarm has been set!"); + isAlarmSet = true; + timer = input.value; + input.value = ""; + } + let intervalId = setInterval(function() { + if(timer >= 0) { + let minutes = Math.floor(timer / 60); + let seconds = timer % 60; + timer--; + console.log("Timer decremented!"); + heading.innerHTML = `Time Remaining: ${minutes.toLocaleString('en-US', { minimumIntegerDigits: 2, useGrouping: false })}:${seconds.toLocaleString('en-US', { minimumIntegerDigits: 2, useGrouping: false })}`; + } + if(timer === -1) { + playAlarm(); + clearInterval(intervalId); + isAlarmSet = false; + } + }, 1000); +} + +function setAlarm() { + let setBtn = document.getElementById("set"); + setBtn.addEventListener("click", setBtnEventListener); +} // DO NOT EDIT BELOW HERE diff --git a/mandatory/2-quotegenerator/index.html b/mandatory/2-quotegenerator/index.html index b6115be..dcb8ac2 100644 --- a/mandatory/2-quotegenerator/index.html +++ b/mandatory/2-quotegenerator/index.html @@ -2,7 +2,6 @@ Quote Generator - - +
+

+

+ +
+ diff --git a/mandatory/2-quotegenerator/quotes.js b/mandatory/2-quotegenerator/quotes.js index 39ab245..d016963 100644 --- a/mandatory/2-quotegenerator/quotes.js +++ b/mandatory/2-quotegenerator/quotes.js @@ -1,3 +1,98 @@ +/* + * This is the event listener that generates new quotes + * every time the button is pressed. + */ +function generateQuote() { + // get all the needed elements into javascript variables + let body = document.body; + let mainDiv = document.getElementsByClassName("quoteContainer"); + let quote = document.getElementById("quote"); + let author = document.getElementById("author"); + let newQuoteBtn = document.getElementById("newQuoteBtn"); + + // pick the quote to be displayed + let quoteOfTheDay = pickFromArray(quotes); + + // update the quote and its author on the page + quote.innerHTML = quoteOfTheDay.quote; + author.innerHTML = "- " + quoteOfTheDay.author; + + // update the theme of the page + + // change the background colours of various elements + body.style.backgroundColor = colorPalette[chosenStyle].pageBackground; + mainDiv[0].style.backgroundColor = colorPalette[chosenStyle].quoteBackground; + newQuoteBtn.style.backgroundColor = colorPalette[chosenStyle].buttonColour; + + // change the font colours of various elements + quote.style.color = colorPalette[chosenStyle].quoteFontColour; + author.style.color = colorPalette[chosenStyle].authorFontColour; + newQuoteBtn.style.color = colorPalette[chosenStyle].buttonFontColour; + + // update the chosen theme for when next time the button is pressed + chosenStyle = (chosenStyle + 1) % numOfStyles; +} + +/* + * Main function of the program + */ +function quoteGenerator() { + let newQuoteBtn = document.getElementById("newQuoteBtn"); + + // attach the event listener to the button + newQuoteBtn.addEventListener("click", generateQuote); +} + +window.onload = generateQuote; +quoteGenerator(); + +// A list of available themes which will be applied to the quotes +const colorPalette = [ + { + pageBackground: "#c7d4db", + quoteBackground: "#ffffff", + buttonColour: "#0ae071", + quoteFontColour: "#48179e", + authorFontColour: "#0ae071", + buttonFontColour: "#48179e", + }, + { + pageBackground: "#f5f6f7", + quoteBackground: "#c9d6d5", + buttonColour: "#e0a315", + quoteFontColour: "#4d7171", + authorFontColour: "#bb570c", + buttonFontColour: "#f6f6f6", + }, + { + pageBackground: "#cca98c", + quoteBackground: "#f5f6f7", + buttonColour: "#12bb65", + quoteFontColour: "#12bb65", + authorFontColour: "#cca98c", + buttonFontColour: "white", + }, + { + pageBackground: "#4e5da4", + quoteBackground: "#e4cb40", + buttonColour: "#4e5da4", + quoteFontColour: "#4e5da4", + authorFontColour: "#4e5da4", + buttonFontColour: "#e4cb40", + }, + { + pageBackground: "#4f6f9e", + quoteBackground: "#eefeef", + buttonColour: "#ea0040", + quoteFontColour: "#2c2a5b", + authorFontColour: "#4f6f9e", + buttonFontColour: "#eefeef", + } +]; + +const numOfStyles = colorPalette.length; +let chosenStyle = 0; + // DO NOT EDIT BELOW HERE // A function which will return one item, at diff --git a/mandatory/2-quotegenerator/style.css b/mandatory/2-quotegenerator/style.css index 63cedf2..f0db72e 100644 --- a/mandatory/2-quotegenerator/style.css +++ b/mandatory/2-quotegenerator/style.css @@ -1 +1,38 @@ /** Write your CSS in here **/ +.quoteContainer { + display: flex; + align-items: center; + flex-direction: column; + margin: 25vh auto; + width: 80%; + max-width: 1080px; +} + +.quoteHeading { + margin: 2rem auto; + text-align: left; + width: 80%; + flex-grow: 1; +} + +.authorHeading { + margin: 1rem auto; + width: 80%; + text-align: right; +} + +.btn { + margin: 1rem auto; + padding: 0.75rem; + width: 10rem; + min-width: 48px; + min-height: 48px; + box-shadow: 0rem 0rem 0.2rem 0.1rem grey; + align-self: flex-end; + font-size: 1.4rem; +} + +#quotationMarks { + font-size: 5rem; + font-family: "Times New Roman"; +} diff --git a/mandatory/3-slideshow/images/italy_1.jpeg b/mandatory/3-slideshow/images/italy_1.jpeg new file mode 100644 index 0000000..f90b85b Binary files /dev/null and b/mandatory/3-slideshow/images/italy_1.jpeg differ diff --git a/mandatory/3-slideshow/images/italy_10.jpeg b/mandatory/3-slideshow/images/italy_10.jpeg new file mode 100644 index 0000000..94800e3 Binary files /dev/null and b/mandatory/3-slideshow/images/italy_10.jpeg differ diff --git a/mandatory/3-slideshow/images/italy_2.jpeg b/mandatory/3-slideshow/images/italy_2.jpeg new file mode 100644 index 0000000..0943234 Binary files /dev/null and b/mandatory/3-slideshow/images/italy_2.jpeg differ diff --git a/mandatory/3-slideshow/images/italy_3.jpeg b/mandatory/3-slideshow/images/italy_3.jpeg new file mode 100644 index 0000000..b538763 Binary files /dev/null and b/mandatory/3-slideshow/images/italy_3.jpeg differ diff --git a/mandatory/3-slideshow/images/italy_4.jpeg b/mandatory/3-slideshow/images/italy_4.jpeg new file mode 100644 index 0000000..c1e3436 Binary files /dev/null and b/mandatory/3-slideshow/images/italy_4.jpeg differ diff --git a/mandatory/3-slideshow/images/italy_5.jpeg b/mandatory/3-slideshow/images/italy_5.jpeg new file mode 100644 index 0000000..2f5fdd2 Binary files /dev/null and b/mandatory/3-slideshow/images/italy_5.jpeg differ diff --git a/mandatory/3-slideshow/images/italy_6.jpeg b/mandatory/3-slideshow/images/italy_6.jpeg new file mode 100644 index 0000000..c2cdf6d Binary files /dev/null and b/mandatory/3-slideshow/images/italy_6.jpeg differ diff --git a/mandatory/3-slideshow/images/italy_7.jpeg b/mandatory/3-slideshow/images/italy_7.jpeg new file mode 100644 index 0000000..5c4be65 Binary files /dev/null and b/mandatory/3-slideshow/images/italy_7.jpeg differ diff --git a/mandatory/3-slideshow/images/italy_8.jpeg b/mandatory/3-slideshow/images/italy_8.jpeg new file mode 100644 index 0000000..2ee39a3 Binary files /dev/null and b/mandatory/3-slideshow/images/italy_8.jpeg differ diff --git a/mandatory/3-slideshow/images/italy_9.jpeg b/mandatory/3-slideshow/images/italy_9.jpeg new file mode 100644 index 0000000..5635dd2 Binary files /dev/null and b/mandatory/3-slideshow/images/italy_9.jpeg differ diff --git a/mandatory/3-slideshow/index.html b/mandatory/3-slideshow/index.html index 39cd40e..5c2b1a7 100644 --- a/mandatory/3-slideshow/index.html +++ b/mandatory/3-slideshow/index.html @@ -2,7 +2,6 @@ Slideshow - - +
+

Enjoy the eclectic view of Italy!

+
+ + poster image + +
+
+ + + +
+
+ diff --git a/mandatory/3-slideshow/slideshow.js b/mandatory/3-slideshow/slideshow.js index b55091c..bb2c20b 100644 --- a/mandatory/3-slideshow/slideshow.js +++ b/mandatory/3-slideshow/slideshow.js @@ -1 +1,107 @@ -// Write your code here +/***********************Global Variables**************************************/ + + +// array containing the img src for the slide show +var images = [ + "images/italy_1.jpeg", + "images/italy_2.jpeg", + "images/italy_3.jpeg", + "images/italy_4.jpeg", + "images/italy_5.jpeg", + "images/italy_6.jpeg", + "images/italy_7.jpeg", + "images/italy_8.jpeg", + "images/italy_9.jpeg", + "images/italy_10.jpeg", +]; + +// starting point of slide show is images[0], +// this variable keeps track of the number of image being displayed from the array +var num=0; + +// flags to identify the present state of slid show +let isSlideShowRunning = false; +let slideShowDirection = "forward"; + + +/***********************Function Definitions**********************************/ + + +// function to update the image and display the next image from array images +function next() { + var slider = document.getElementById('slider-img'); + num++; + if(num >= images.length) + { + num=0; + } + slider.src = images[num]; +} + +// function to update the image and display the previous image from array images +function previous() { + var slider = document.getElementById('slider-img'); + num--; + if(num < 0) + { + num = images.length-1; + } + slider.src = images[num]; +} + +// updates the image forward based on the slide show state flags +function updateImageForward(intervalId) { + if(isSlideShowRunning && slideShowDirection === "forward") { + next(); + } + else { + clearInterval(intervalId); + } +} + +// updates the image backward based on the slide show state flags +function updateImageBackward(intervalId) { + if(isSlideShowRunning && slideShowDirection === "back") { + previous(); + } + else { + clearInterval(intervalId); + } +} + +// function that controls the slide show including all the event listeners +function slideShow () { + let forwardBtn = document.getElementById("forward-slide-show"); + let backBtn = document.getElementById("back-slide-show"); + let stopBtn = document.getElementById("stop-slide-show"); + + // set the event listener for "Stop" button + stopBtn.addEventListener("click", function() { + isSlideShowRunning = false; + }) + + // set the event listener for the "Forward" button + forwardBtn.addEventListener("click", function() { + isSlideShowRunning = true; + slideShowDirection = "forward"; + let intervalId = setInterval(function() { + updateImageForward(intervalId) + }, 1000); + }); + + // set the event listener for the "back" button + backBtn.addEventListener("click", function() { + isSlideShowRunning = true; + slideShowDirection = "back"; + let intervalId = setInterval(function() { + updateImageBackward(intervalId) + }, 1000); + }); +} + + +/***********************Function Calls*****************************************/ + + +// call the function slideShow() +slideShow(); diff --git a/mandatory/3-slideshow/style.css b/mandatory/3-slideshow/style.css index 63cedf2..ed412ea 100644 --- a/mandatory/3-slideshow/style.css +++ b/mandatory/3-slideshow/style.css @@ -1 +1,102 @@ /** Write your CSS in here **/ +html { + /* Style properties inherited by the whole document */ + font-family: Calibri, Arial, Helvetica, sans-serif; + font-size: 10px; /* 1rem = 10px */ +} + +body { + /* Properties that are applied to the body of the html page */ + width: 100%; + margin: auto; + text-align: justify; + align-items: center; + justify-content: center; +} + +main { + display: flex; + flex-direction: column; +} + +.heading { + text-align: center; + margin: 2rem auto; + color: #261b4f; + font-size: 5rem; + font-weight: 700; +} + +#highlight { + color: #e7b333; +} + +#slider-img-container { + text-align: center; + width: 60%; + display: flex; + justify-content: center; + align-items: center; + margin: auto; +} + +#slider-img { + object-fit: cover; /* to keep the img within the container */ + object-position: center; /* position it to the center of the container */ + margin: auto; + width: 90%; + height: 70vh; + border-radius: 1rem; + box-shadow: -10px 10px 20px rgba(0, 0, 0, 0.18), + -5px 6px 10px rgba(157, 45, 43, 0.5); +} + +.slider-button { + border-radius: 50%; + font-size: 3em; + background-color: #261b4f; + color: white; + border-color: transparent; + box-shadow: 0px 10px 15px rgba(0, 0, 0, 0.19); + outline: none; +} + +.slider-button:hover { + background-color: #14d183; + transform: scale(1.3); + color: white; + outline: none; +} + +.slider-button:focus { + outline: none; +} + +#slide-show-button-container { + margin: 1rem; + display: flex; + flex-direction: row; + justify-content: center; +} + +.slide-show { + margin: 1rem; + min-width: 48px; + min-height: 48px; + width: 15rem; + border-radius: 1rem; + font-size: 2em; + text-align: center; + background-color: #261b4f; + color: white; + border: none; + box-shadow: 0px 10px 15px rgba(0, 0, 0, 0.19); + outline: none; +} + +.slide-show:focus { + outline: none; + background-color: #e7b333; + transform: scale(1.05); + color: white; +}