From 3dd12a8cbf2512be03934b98e75bbaf32cec6938 Mon Sep 17 00:00:00 2001
From: Andrej Rasevic <andrej@rasevicengineering.com>
Date: Tue, 8 Jun 2021 15:59:53 -0400
Subject: [PATCH] adding Exercise 2

---
 Exercises/Exercise2/Exercise2Description.md |  19 +
 Exercises/Exercise2/exercise2.html          | 483 ++++++++++++++++++++
 Exercises/Exercise2/testing.md              |   0
 Exercises/Exercise2/tests.js                |  24 +
 4 files changed, 526 insertions(+)
 create mode 100644 Exercises/Exercise2/Exercise2Description.md
 create mode 100644 Exercises/Exercise2/exercise2.html
 create mode 100644 Exercises/Exercise2/testing.md
 create mode 100644 Exercises/Exercise2/tests.js

diff --git a/Exercises/Exercise2/Exercise2Description.md b/Exercises/Exercise2/Exercise2Description.md
new file mode 100644
index 0000000..6a6c05b
--- /dev/null
+++ b/Exercises/Exercise2/Exercise2Description.md
@@ -0,0 +1,19 @@
+# Exercise 2:
+
+## Due Date: Saturday January 16, 11:59 PM 
+
+## Objectives: To get familiar with javascript functional prototypes, template strings, arrays and higher order javascript array functions.
+
+## Specifications/Requirements
+
+1. Description:
+   To complete this exercise you will be working in `exercise2.html` where you will be using the javascript functional prototype provided in the comments in order to obtain the required data and display it in the console using template strings to format output.
+
+2. Formating and output:
+   You will be logging all your results to the console, and the specification as to how the ouput should look are included in the comments above each exercise. If there are no specifications for an exercises output you may assume that there is no special formating associated with that exercise (refer to the recordings for how it should appear). 
+
+3. Fix the getPresidentInfo() function:  
+   The `getPresidentInfo()` function will create a new div in the dom every time the user clicks the `Get President Name` button. There is an error in the code. It creates a new div to store the name of the president with the same value for the id attribute. You need to update this function so it creates a unique id for every call of this event listener.
+
+4. Additional Notes:
+   You should not alter the presidents data we provide you with. This should go without saying, but you should not hardcode your results, we will check your submissions to make sure this does not happen. You should use the functional array prototypes that we have gone over in class and that are mentioned in this exercise (map, sort, filter, reduce), using for loops, for..of loops, while loops, etc will result in a substantial amount of point deduction.
diff --git a/Exercises/Exercise2/exercise2.html b/Exercises/Exercise2/exercise2.html
new file mode 100644
index 0000000..5e444e3
--- /dev/null
+++ b/Exercises/Exercise2/exercise2.html
@@ -0,0 +1,483 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <title></title>
+  </head>
+  <body>
+    <h3>Open up the developer console for results!</h3>
+    <label for="president">Select a president (between 1 and 45):</label>
+    <input type="text " id="president" name="president" size="4">
+    <button onclick="getPresidentInfo()">Get President Name</button>
+    <div id="container">
+
+    </div> 
+    <script>
+      const presidents = [
+        {
+          number: 1,
+          president: "George Washington",
+          birth_year: 1732,
+          death_year: 1799,
+          took_office: "1789-04-30",
+          left_office: "1797-03-04",
+          party: "No Party"
+        },
+        {
+          number: 2,
+          president: "John Adams",
+          birth_year: 1735,
+          death_year: 1826,
+          took_office: "1797-03-04",
+          left_office: "1801-03-04",
+          party: "Federalist"
+        },
+        {
+          number: 3,
+          president: "Thomas Jefferson",
+          birth_year: 1743,
+          death_year: 1826,
+          took_office: "1801-03-04",
+          left_office: "1809-03-04",
+          party: "Democratic-Republican"
+        },
+        {
+          number: 4,
+          president: "James Madison",
+          birth_year: 1751,
+          death_year: 1836,
+          took_office: "1809-03-04",
+          left_office: "1817-03-04",
+          party: "Democratic-Republican"
+        },
+        {
+          number: 5,
+          president: "James Monroe",
+          birth_year: 1758,
+          death_year: 1831,
+          took_office: "1817-03-04",
+          left_office: "1825-03-04",
+          party: "Democratic-Republican"
+        },
+        {
+          number: 6,
+          president: "John Quincy Adams",
+          birth_year: 1767,
+          death_year: 1848,
+          took_office: "1825-03-04",
+          left_office: "1829-03-04",
+          party: "Democratic-Republican"
+        },
+        {
+          number: 7,
+          president: "Andrew Jackson",
+          birth_year: 1767,
+          death_year: 1845,
+          took_office: "1829-03-04",
+          left_office: "1837-03-04",
+          party: "Democratic"
+        },
+        {
+          number: 8,
+          president: "Martin Van Buren",
+          birth_year: 1782,
+          death_year: 1862,
+          took_office: "1837-03-04",
+          left_office: "1841-03-04",
+          party: "Democratic"
+        },
+        {
+          number: 9,
+          president: "William Henry Harrison",
+          birth_year: 1773,
+          death_year: 1841,
+          took_office: "1841-03-04",
+          left_office: "1841-04-04",
+          party: "Whig"
+        },
+        {
+          number: 10,
+          president: "John Tyler",
+          birth_year: 1790,
+          death_year: 1862,
+          took_office: "1841-04-04",
+          left_office: "1845-03-04",
+          party: "Whig"
+        },
+        {
+          number: 11,
+          president: "James K. Polk",
+          birth_year: 1795,
+          death_year: 1849,
+          took_office: "1845-03-04",
+          left_office: "1849-03-04",
+          party: "Democratic"
+        },
+        {
+          number: 12,
+          president: "Zachary Taylor",
+          birth_year: 1784,
+          death_year: 1850,
+          took_office: "1849-03-04",
+          left_office: "1850-07-09",
+          party: "Whig"
+        },
+        {
+          number: 13,
+          president: "Millard Fillmore",
+          birth_year: 1800,
+          death_year: 1874,
+          took_office: "1850-07-09",
+          left_office: "1853-03-04",
+          party: "Whig"
+        },
+        {
+          number: 14,
+          president: "Franklin Pierce",
+          birth_year: 1804,
+          death_year: 1869,
+          took_office: "1853-03-04",
+          left_office: "1857-03-04",
+          party: "Democratic"
+        },
+        {
+          number: 15,
+          president: "James Buchanan",
+          birth_year: 1791,
+          death_year: 1868,
+          took_office: "1857-03-04",
+          left_office: "1861-03-04",
+          party: "Democratic"
+        },
+        {
+          number: 16,
+          president: "Abraham Lincoln",
+          birth_year: 1809,
+          death_year: 1865,
+          took_office: "1861-03-04",
+          left_office: "1865-04-15",
+          party: "Republican"
+        },
+        {
+          number: 17,
+          president: "Andrew Johnson",
+          birth_year: 1808,
+          death_year: 1875,
+          took_office: "1865-04-15",
+          left_office: "1869-03-04",
+          party: "Democratic"
+        },
+        {
+          number: 18,
+          president: "Ulysses S. Grant",
+          birth_year: 1822,
+          death_year: 1885,
+          took_office: "1869-03-04",
+          left_office: "1877-03-04",
+          party: "Republican"
+        },
+        {
+          number: 19,
+          president: "Rutherford B. Hayes",
+          birth_year: 1822,
+          death_year: 1893,
+          took_office: "1877-03-04",
+          left_office: "1881-03-04",
+          party: "Republican"
+        },
+        {
+          number: 20,
+          president: "James A. Garfield",
+          birth_year: 1831,
+          death_year: 1881,
+          took_office: "1881-03-04",
+          left_office: "1881-09-19",
+          party: "Republican"
+        },
+        {
+          number: 21,
+          president: "Chester A. Arthur",
+          birth_year: 1829,
+          death_year: 1886,
+          took_office: "1881-09-19",
+          left_office: "1885-03-04",
+          party: "Republican"
+        },
+        {
+          number: 22,
+          president: "Grover Cleveland",
+          birth_year: 1837,
+          death_year: 1908,
+          took_office: "1885-03-04",
+          left_office: "1889-03-04",
+          party: "Democratic"
+        },
+        {
+          number: 23,
+          president: "Benjamin Harrison",
+          birth_year: 1833,
+          death_year: 1901,
+          took_office: "1889-03-04",
+          left_office: "1893-03-04",
+          party: "Republican"
+        },
+        {
+          number: 24,
+          president: "Grover Cleveland",
+          birth_year: 1837,
+          death_year: 1908,
+          took_office: "1893-03-04",
+          left_office: "1897-03-04",
+          party: "Democratic"
+        },
+        {
+          number: 25,
+          president: "William McKinley",
+          birth_year: 1843,
+          death_year: 1901,
+          took_office: "1897-03-04",
+          left_office: "1901-09-14",
+          party: "Republican"
+        },
+        {
+          number: 26,
+          president: "Theodore Roosevelt",
+          birth_year: 1858,
+          death_year: 1919,
+          took_office: "1901-09-14",
+          left_office: "1909-03-04",
+          party: "Republican"
+        },
+        {
+          number: 27,
+          president: "William Howard Taft",
+          birth_year: 1857,
+          death_year: 1930,
+          took_office: "1909-03-04",
+          left_office: "1913-03-04",
+          party: "Republican"
+        },
+        {
+          number: 28,
+          president: "Woodrow Wilson",
+          birth_year: 1856,
+          death_year: 1924,
+          took_office: "1913-03-04",
+          left_office: "1921-03-04",
+          party: "Democratic"
+        },
+        {
+          number: 29,
+          president: "Warren G. Harding",
+          birth_year: 1865,
+          death_year: 1923,
+          took_office: "1921-03-04",
+          left_office: "1923-08-02",
+          party: "Republican"
+        },
+        {
+          number: 30,
+          president: "Calvin Coolidge",
+          birth_year: 1872,
+          death_year: 1933,
+          took_office: "1923-08-02",
+          left_office: "1929-03-04",
+          party: "Republican"
+        },
+        {
+          number: 31,
+          president: "Herbert Hoover",
+          birth_year: 1874,
+          death_year: 1964,
+          took_office: "1929-03-04",
+          left_office: "1933-03-04",
+          party: "Republican"
+        },
+        {
+          number: 32,
+          president: "Franklin D. Roosevelt",
+          birth_year: 1882,
+          death_year: 1945,
+          took_office: "1933-03-04",
+          left_office: "1945-04-12",
+          party: "Democratic"
+        },
+        {
+          number: 33,
+          president: "Harry S. Truman",
+          birth_year: 1884,
+          death_year: 1972,
+          took_office: "1945-04-12",
+          left_office: "1953-01-20",
+          party: "Democratic"
+        },
+        {
+          number: 34,
+          president: "Dwight D. Eisenhower",
+          birth_year: 1890,
+          death_year: 1969,
+          took_office: "1953-01-20",
+          left_office: "1961-01-20",
+          party: "Republican"
+        },
+        {
+          number: 35,
+          president: "John F. Kennedy",
+          birth_year: 1917,
+          death_year: 1963,
+          took_office: "1961-01-20",
+          left_office: "1963-11-22",
+          party: "Democratic"
+        },
+        {
+          number: 36,
+          president: "Lyndon B. Johnson",
+          birth_year: 1908,
+          death_year: 1973,
+          took_office: "1963-11-22",
+          left_office: "1969-01-20",
+          party: "Democratic"
+        },
+        {
+          number: 37,
+          president: "Richard Nixon",
+          birth_year: 1913,
+          death_year: 1994,
+          took_office: "1969-01-20",
+          left_office: "1974-08-09",
+          party: "Republican"
+        },
+        {
+          number: 38,
+          president: "Gerald Ford",
+          birth_year: 1913,
+          death_year: 2006,
+          took_office: "1974-08-09",
+          left_office: "1977-01-20",
+          party: "Republican"
+        },
+        {
+          number: 39,
+          president: "Jimmy Carter",
+          birth_year: 1924,
+          death_year: null,
+          took_office: "1977-01-20",
+          left_office: "1981-01-20",
+          party: "Democratic"
+        },
+        {
+          number: 40,
+          president: "Ronald Reagan",
+          birth_year: 1911,
+          death_year: 2004,
+          took_office: "1981-01-20",
+          left_office: "1989-01-20",
+          party: "Republican"
+        },
+        {
+          number: 41,
+          president: "George H. W. Bush",
+          birth_year: 1924,
+          death_year: 2018,
+          took_office: "1989-01-20",
+          left_office: "1993-01-20",
+          party: "Republican"
+        },
+        {
+          number: 42,
+          president: "Bill Clinton",
+          birth_year: 1946,
+          death_year: null,
+          took_office: "1993-01-20",
+          left_office: "2001-01-20",
+          party: "Democratic"
+        },
+        {
+          number: 43,
+          president: "George W. Bush",
+          birth_year: 1946,
+          death_year: null,
+          took_office: "2001-01-20",
+          left_office: "2009-01-20",
+          party: "Republican"
+        },
+        {
+          number: 44,
+          president: "Barack Obama",
+          birth_year: 1961,
+          death_year: null,
+          took_office: "2009-01-20",
+          left_office: "2017-01-20",
+          party: "Democratic"
+        },
+        {
+          number: 45,
+          president: "Donald J. Trump",
+          birth_year: 1946,
+          death_year: null,
+          took_office: "2017-01-20",
+          left_office: null,
+          party: "Republican"
+        }
+      ];
+
+      function getPresidentInfo() {
+        let presidentNumber = document.getElementById('president');
+        let number = presidentNumber.value;
+        let container = document.getElementById('container');
+        let newDiv = document.createElement('div')
+        newDiv.setAttribute('id', 'output')
+        newDiv.innerHTML = presidents[number]['president']
+        container.appendChild(newDiv)
+      }
+
+      // Part 1 Questions
+      //================================================================================================
+
+      // Array.prototype.filter()
+      // 1. Filter the list of presidents for those who were born in the 1800's
+        let result1;
+
+        console.table(result1);
+
+      // Array.prototype.map()
+      // 2. Map the presidents name and party to a seperate array. Format: <president_name> (<party>)
+
+        let result2;
+
+        console.table(result2);
+
+      // Array.prototype.sort()
+      // 3. Sort the presidents by birthdate, by descending order (most recent to least recent dates)
+
+        let result3;
+
+        console.table(result3);
+
+      // Array.prototype.reduce()
+      // 4. How many years combined did all the presidents live? (Hint: Lookout for the presidents who are still alive)
+
+        let result4;
+
+        console.log(`Number of combined years presidents have lived: ${result4}`);
+
+      // sort/map Exercise
+      // 5. Sort the presidents names by name in ascending order, and map the time they took office to a new list. Format: <president_name> - <took_office>
+
+       let result5;
+
+        console.table(result5);
+
+      // Array.prototype.reduce()
+      // Hint: to check if a property exists in an object you can simply
+      // have the following check: if (obj.property_name)
+      // if the property exists on the obj object that will return true
+      // Additonally, reduce can take an empty object as its accumulator.
+      // 6. Sum up the number of times each political party held the presidency
+
+        let result6;
+
+        console.table(result6);
+    </script>
+  </body>
+</html>
diff --git a/Exercises/Exercise2/testing.md b/Exercises/Exercise2/testing.md
new file mode 100644
index 0000000..e69de29
diff --git a/Exercises/Exercise2/tests.js b/Exercises/Exercise2/tests.js
new file mode 100644
index 0000000..bd0ba3d
--- /dev/null
+++ b/Exercises/Exercise2/tests.js
@@ -0,0 +1,24 @@
+let testData = [
+    {},
+    {},
+    {},
+    {}
+]
+// objects with bdays pre 1800's, during 1800's and post 1800's
+
+function filterbasedOnBirthyear(data) {
+
+}
+
+// filter testData based on implementation in script
+//let results = testData.filter()
+
+functionTestResultsForFilter(result,    ) {
+    if (result === expected) {
+        console.log ("filterTestPassed")
+    } else {
+        console.error('Fileter test failed')
+    }
+}
+
+functionTestResultsForFilter(results, testData)
\ No newline at end of file
-- 
GitLab