diff --git a/InClass/Callbacks/exercise-1/exercise.js b/InClass/Callbacks/exercise-1/exercise.js index 40f06b0..c40354f 100644 --- a/InClass/Callbacks/exercise-1/exercise.js +++ b/InClass/Callbacks/exercise-1/exercise.js @@ -1,13 +1,23 @@ -/* -================ -EXERCISE 1 +let div = document.getElementById("main"); -Task 1 -Using setTimeout, change the background colour of the page after 5 seconds (5000 milliseconds). +function changeColour() { + div.style.backgroundColor = "yellow"; +} -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 +setTimeout(changeColour, 5000); -Prefer to work on a codepen? https://codepen.io/makanti/pen/abOreLg -================ -*/ \ No newline at end of file + +// task 2 + +let i = 0; +let colours = ["pink", "red", "green" "#efefef", "#0ae071"]; + +function changeColourFiveSeconds() { + div.style.backgroundColor = colours[i]; + i++; + + if (i > colours.length) { + i = 0; + }; +}; +setInterval(changeColourFiveSeconds, 5000); \ No newline at end of file diff --git a/InClass/Callbacks/exercise-2/exercise.js b/InClass/Callbacks/exercise-2/exercise.js index eca9595..8e434fc 100644 --- a/InClass/Callbacks/exercise-2/exercise.js +++ b/InClass/Callbacks/exercise-2/exercise.js @@ -63,8 +63,45 @@ const movies = [ // create showMovies function +function showMovies () { + +let span = document.getElementById("movies-number"); +span.innerHTML = movies.length; + +for (let i = 0; i < movies.length; i ++) { +let div = document.getElementById("all-movies"); +let p = document.createElement("p"); + +setTimeout(function () { + p.innerHTML = `${movies[i].title} - ${movies[i].director}`; + delete movies[i]; + div.appendChild(p); +}, 1000); +}; +}; + +showMovies(); + + // create a new movie object for your favorite movie +let myMovies = { + title: "Hush", + director: "Mike Flanagan", + type: "Horror/Thriller", + haveWatched: true, +}; + + // create addMovies function + +function addMovies (movie) { + setTimeout(function () { + movies.push(movie); + showMovies(movies); + }, 2000); + }; + +addMovies(myMovies); diff --git a/InClass/Callbacks/exercise-2/index.html b/InClass/Callbacks/exercise-2/index.html index bc9654c..ddec193 100644 --- a/InClass/Callbacks/exercise-2/index.html +++ b/InClass/Callbacks/exercise-2/index.html @@ -23,6 +23,26 @@
Number of movies:
+ + + + + +