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:
+