├── coding-exercise-01
└── solution
│ └── index.html
├── coding-exercise-02
└── solution
│ └── index.html
├── coding-exercise-03
└── solution
│ └── index.html
├── coding-exercise-04
└── solution
│ └── index.html
├── coding-exercise-05
└── solution
│ └── index.html
├── coding-exercise-06
└── solution
│ └── index.html
├── coding-exercise-07
└── solution
│ ├── index.html
│ └── styles.css
├── coding-exercise-08
└── solution
│ ├── app.css
│ └── index.html
├── coding-exercise-09
└── solution
│ ├── app.css
│ └── index.html
├── coding-exercise-10
└── solution
│ ├── app.css
│ └── index.html
├── coding-exercise-11
└── solution
│ ├── NO_TOUCHING.css
│ ├── app.css
│ └── index.html
├── coding-exercise-12
└── solution
│ ├── app.css
│ └── index.html
├── coding-exercise-13
└── solution
│ └── index.html
├── coding-exercise-14
└── solution
│ └── index.html
├── coding-exercise-15
└── solution
│ └── index.js
├── coding-exercise-16
└── solution
│ └── index.js
├── coding-exercise-17
└── solution
│ └── index.js
├── coding-exercise-18
└── solution
│ └── index.js
├── coding-exercise-19
└── solution
│ └── index.js
├── coding-exercise-20
└── solution
│ └── index.js
├── coding-exercise-21
└── solution
│ └── index.js
├── coding-exercise-22
└── solution
│ └── index.js
├── coding-exercise-23
└── solution
│ └── index.js
├── coding-exercise-24
└── solution
│ └── index.js
├── coding-exercise-25
└── solution
│ └── index.js
├── coding-exercise-26
└── solution
│ └── index.js
├── coding-exercise-27
└── solution
│ └── index.js
├── coding-exercise-28
└── solution
│ └── index.js
├── coding-exercise-29
└── solution
│ └── index.js
├── coding-exercise-30
└── solution
│ └── index.js
├── coding-exercise-31
└── solution
│ └── index.js
├── coding-exercise-32
└── solution
│ └── index.js
├── coding-exercise-33
└── solution
│ └── index.js
├── coding-exercise-34
└── solution
│ └── index.js
├── coding-exercise-35
└── solution
│ └── index.js
├── coding-exercise-36
├── solution-2
│ └── index.js
└── solution
│ └── index.js
├── coding-exercise-37
└── solution
│ └── index.js
├── coding-exercise-38
└── solution
│ └── index.js
├── coding-exercise-39
└── solution
│ └── index.js
├── coding-exercise-40
├── solution-2
│ └── index.js
├── solution-3
│ └── index.js
└── solution
│ └── index.js
├── coding-exercise-41
├── solution-2
│ └── index.js
└── solution
│ └── index.js
├── coding-exercise-42
├── solution-2
│ └── index.js
└── solution
│ └── index.js
├── coding-exercise-43
├── solution-2
│ └── index.js
├── solution-3
│ └── index.js
├── solution-4
│ └── index.js
├── solution-5
│ └── index.js
└── solution
│ └── index.js
├── coding-exercise-44
└── solution
│ └── index.js
├── coding-exercise-45
└── solution
│ └── index.js
├── coding-exercise-46
└── solution
│ └── index.js
├── coding-exercise-47
└── solution
│ └── index.js
├── coding-exercise-48
└── solution
│ └── index.js
├── coding-exercise-49
└── solution
│ └── index.js
├── coding-exercise-50
└── solution
│ └── index.js
├── coding-exercise-51
└── solution
│ ├── app.js
│ └── index.html
├── coding-exercise-52
└── solution
│ ├── app.css
│ ├── app.js
│ └── index.html
├── coding-exercise-53
└── solution
│ ├── app.js
│ └── index.html
├── coding-exercise-54
└── solution
│ ├── app.js
│ └── index.html
├── coding-exercise-55
└── solution
│ ├── app.js
│ └── index.html
├── coding-exercise-56
└── solution
│ ├── app.js
│ └── index.html
├── coding-exercise-57
├── solution-2
│ ├── app.css
│ ├── app.js
│ └── index.html
└── solution
│ ├── app.css
│ ├── app.js
│ └── index.html
├── coding-exercise-58
└── solution
│ ├── app.js
│ └── index.html
├── coding-exercise-59
└── solution
│ └── index.html
├── coding-exercise-60
└── solution
│ ├── app.js
│ └── index.html
├── coding-exercise-61
├── solution-2
│ ├── app.js
│ └── index.html
└── solution
│ ├── app.js
│ └── index.html
├── coding-exercise-62
├── solution-2
│ ├── app.js
│ └── index.html
├── solution-3
│ ├── app.js
│ └── index.html
└── solution
│ ├── app.js
│ └── index.html
├── quiz-01
└── quiz-01.md
├── quiz-02
└── quiz-02.md
├── quiz-03
└── quiz-03.md
├── quiz-04
└── quiz-04.md
├── quiz-05
└── quiz-05.md
├── quiz-06
└── quiz-06.md
├── quiz-07
└── quiz-07.md
└── readme.md
/coding-exercise-01/solution/index.html:
--------------------------------------------------------------------------------
1 |
Pangolin
2 | Intro
3 |
4 | Pangolins, sometimes known as scaly anteaters, are mammals of the order Pholidota (from Ancient Greek φολῐ́ς, "horny
5 | scale"). The one extant family, Manidae, has three genera: Manis, Phataginus and Smutsia. Manis comprises the four
6 | species found in Asia, while Phataginus and Smutsia include two species each, all found in Sub-Saharan Africa. These
7 | species range in size from 30 to 100 cm (12 to 39 in). A number of extinct pangolin species are also known.
8 |
9 | Description
10 |
11 | Pangolins have large, protective keratin scales covering their skin; they are the only known mammals with this
12 | feature. They live in hollow trees or burrows, depending on the species. Pangolins are nocturnal, and their diet
13 | consists of mainly ants and termites, which they capture using their long tongues. They tend to be solitary animals,
14 | meeting only to mate and produce a litter of one to three offspring, which they raise for about two years.
15 |
16 | Poaching
17 |
18 | Pangolins are threatened by poaching (for their meat and scales, which are used in Chinese traditional medicine) and
19 | heavy deforestation of their natural habitats, and are the most trafficked mammals in the world.As of January 2020,
20 | of the eight species of pangolin, three (Manis culionensis, M. pentadactyla and M. javanica) are listed as
21 | critically endangered, three (Phataginus tricuspis, Manis crassicaudata and Smutsia gigantea) are listed as
22 | endangered and two (Phataginus tetradactyla and Smutsia temminckii) are listed as vulnerable on the Red List of
23 | Threatened Species of the International Union for Conservation of Nature.
--------------------------------------------------------------------------------
/coding-exercise-02/solution/index.html:
--------------------------------------------------------------------------------
1 | Movies
2 | My Top 3 Movies:
3 |
4 | Amadeus
5 | Stand By Me
6 | Amelie
7 |
8 |
9 | Other Good Movies:
10 |
11 | Alien
12 | Parasite
13 | Annie Hall
14 |
--------------------------------------------------------------------------------
/coding-exercise-03/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/coding-exercise-04/solution/index.html:
--------------------------------------------------------------------------------
1 | ☃Snowman Productions ®
--------------------------------------------------------------------------------
/coding-exercise-05/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Subscription
5 | Price
6 | Support
7 |
8 |
9 |
10 |
11 | Free
12 | Free
13 | N/A
14 |
15 |
16 | Personal
17 | $9.99
18 | Weekdays
19 |
20 |
21 | Business
22 | 49.99
23 | 24/7
24 |
25 |
26 |
--------------------------------------------------------------------------------
/coding-exercise-06/solution/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/coding-exercise-07/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hey!
5 |
6 |
7 |
8 | Please make me green
9 | This is so ugly
10 | Kogi enamel pin polaroid, meditation hammock fashion axe bespoke viral mixtape XOXO tote bag artisan bushwick copper mug poutine. Yuccie humblebrag shabby chic tumeric raclette cronut migas blue bottle. Brooklyn stumptown offal hell of, church-key try-hard hot chicken truffaut. Hell of pok pok microdosing cold-pressed XOXO vice prism yuccie, photo booth actually enamel pin deep v semiotics helvetica. Mixtape four dollar toast butcher yuccie heirloom.
11 | Sign Up
12 |
13 |
--------------------------------------------------------------------------------
/coding-exercise-07/solution/styles.css:
--------------------------------------------------------------------------------
1 | h1 {
2 | color: green;
3 | }
4 |
5 | h2 {
6 | color: magenta;
7 | }
8 |
9 | p {
10 | background-color: black;
11 | color: white;
12 | }
13 |
14 | button {
15 | color: red;
16 | background-color: pink;
17 | }
--------------------------------------------------------------------------------
/coding-exercise-08/solution/app.css:
--------------------------------------------------------------------------------
1 | h1 {
2 | text-transform: uppercase;
3 | font-family: monospace;
4 | font-weight: 100;
5 | font-size: 40px;
6 | letter-spacing: 20px;
7 | text-align: center;
8 | text-decoration: underline wavy plum;
9 | }
--------------------------------------------------------------------------------
/coding-exercise-08/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hipster Logo
5 |
6 |
7 |
8 | Purple Grain
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/coding-exercise-09/solution/app.css:
--------------------------------------------------------------------------------
1 | /* Make all LI's blue */
2 | li {
3 | color: blue;
4 | }
5 |
6 | /* Make everything with the class of 'done' grey*/
7 | .done {
8 | color: grey;
9 | }
10 |
11 | /* Make the element with the id of 'clear' have a red BG and white text */
12 | #clear {
13 | background-color: red;
14 | color: white;
15 | }
--------------------------------------------------------------------------------
/coding-exercise-09/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Basic Selectors Practice
5 |
6 |
7 |
8 | Todos
9 |
10 | Walk Chickens
11 | Clean Out Coop
12 | Collect Chicken Eggs
13 | Incubate Chicken Eggs
14 | Hatch New Chickens!
15 |
16 | Clear List
17 | Add Todo
18 |
19 |
--------------------------------------------------------------------------------
/coding-exercise-10/solution/app.css:
--------------------------------------------------------------------------------
1 | header a {
2 | font-size: 30px;
3 | color: teal;
4 | }
5 |
6 | #dislikes a {
7 | font-weight: bold;
8 | color: red;
9 | }
--------------------------------------------------------------------------------
/coding-exercise-10/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Descendant Combinator Practice
5 |
6 |
7 |
8 |
13 |
14 |
15 | I like to eat popcorn and donuts
16 |
17 |
18 |
19 | I hate eating pickles and beets
20 |
21 |
22 |
--------------------------------------------------------------------------------
/coding-exercise-11/solution/NO_TOUCHING.css:
--------------------------------------------------------------------------------
1 | /* DO NOT TOUCH THIS FILE!!! */
2 | .square {
3 | width: 100px;
4 | height: 100px;
5 | box-sizing: border-box;
6 | border: 1px solid black;
7 | }
8 |
9 | /* DO NOT TOUCH THIS FILE!!! */
10 | /* THIS CODE WILL MAKE SENSE ONCE WE COVER FLEXBOX! */
11 | #board {
12 | display: flex;
13 | margin: 0 auto;
14 | width: 500px;
15 | flex-wrap: wrap;
16 | }
17 |
18 | /* DO NOT TOUCH THIS FILE!!! */
--------------------------------------------------------------------------------
/coding-exercise-11/solution/app.css:
--------------------------------------------------------------------------------
1 | .square:nth-child(odd) {
2 | background-color: red;
3 | }
4 |
5 | .square:nth-child(even) {
6 | background-color: black;
7 | }
8 |
9 | /*Another approach:*/
10 | /*
11 | .square:nth-of-type(2n) {
12 | background-color: black;
13 | }
14 |
15 | .square:nth-of-type(2n+1) {
16 | background-color: red;
17 | }
18 | */
--------------------------------------------------------------------------------
/coding-exercise-11/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Checkerboard
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/coding-exercise-12/solution/app.css:
--------------------------------------------------------------------------------
1 | .card {
2 | width: 210px;
3 | border: 1px solid grey;
4 | border-radius: 5px;
5 | text-align: center;
6 | }
7 |
8 | img {
9 | width: 200px;
10 | border: 5px solid rgb(236, 183, 191);
11 | border-radius: 50%;
12 | }
--------------------------------------------------------------------------------
/coding-exercise-12/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Box Model Practice
5 |
6 |
7 |
8 |
9 |
10 |
I Am Dog
11 |
12 |
13 |
--------------------------------------------------------------------------------
/coding-exercise-13/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Flexbox Exercise
5 |
6 |
8 |
9 |
10 |
11 | Bad News
12 |
13 | You are going to die one day! It sucks, but it's normal :(
14 |
15 | Come To Terms With
16 | Continue To Deny
17 |
18 |
19 |
--------------------------------------------------------------------------------
/coding-exercise-14/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Bootstrap Grid Exercise
5 |
6 |
8 |
9 |
10 |
11 |
12 |
13 | One Third
14 |
15 |
16 | Two Thirds
17 |
18 |
19 |
20 |
21 | One Quarter
22 |
23 |
24 | One Half
25 |
26 |
27 | One Quarter
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/coding-exercise-15/solution/index.js:
--------------------------------------------------------------------------------
1 | let myLuckyNumber = 37;
2 | let octopusLimbs = 8;
--------------------------------------------------------------------------------
/coding-exercise-16/solution/index.js:
--------------------------------------------------------------------------------
1 | const boilingPointC = 100;
2 | const boilingPointF = 212;
--------------------------------------------------------------------------------
/coding-exercise-17/solution/index.js:
--------------------------------------------------------------------------------
1 | const bestColor = "purple";
2 | const quote = 'You had me at "hello"';
--------------------------------------------------------------------------------
/coding-exercise-18/solution/index.js:
--------------------------------------------------------------------------------
1 | // DON'T TOUCH THIS LINE!
2 | const message = " TASTE THE RAINBOW! "; // DON'T CHANGE THIS LINE PLEASE!
3 |
4 | // YOUR CODE BELOW THIS LINE:
5 | const whisper = message.toLowerCase().trim();
--------------------------------------------------------------------------------
/coding-exercise-19/solution/index.js:
--------------------------------------------------------------------------------
1 | // DON'T TOUCH THIS LINE! (please)
2 | const word = 'skateboard';
3 |
4 | // YOUR CODE BELOW THIS LINE:
5 | const facialHair = word.slice(5).replace('o', 'e');
--------------------------------------------------------------------------------
/coding-exercise-20/solution/index.js:
--------------------------------------------------------------------------------
1 | // NO TOUCHING! (please)
2 | const die1 = Math.floor(Math.random() * 6) + 1; // random number from 1-6
3 | const die2 = Math.floor(Math.random() * 6) + 1; // random number from 1-6
4 |
5 | // YOUR CODE BELOW THIS LINE:
6 | const roll = `You rolled a ${die1} and a ${die2}. They sum to ${die1 + die2}`;
--------------------------------------------------------------------------------
/coding-exercise-21/solution/index.js:
--------------------------------------------------------------------------------
1 | function isEven(num) {
2 | if (num % 2 === 0) {
3 | console.log('even');
4 | }
5 | }
--------------------------------------------------------------------------------
/coding-exercise-22/solution/index.js:
--------------------------------------------------------------------------------
1 | function getColor(phrase) {
2 | if (phrase === 'stop') {
3 | console.log('red');
4 | } else if (phrase === 'slow') {
5 | console.log('yellow');
6 | } else if (phrase === 'go') {
7 | console.log('green');
8 | } else {
9 | console.log('purple');
10 | }
11 | }
--------------------------------------------------------------------------------
/coding-exercise-23/solution/index.js:
--------------------------------------------------------------------------------
1 | // Change the value of num, so that "YOU GOT ME!" prints out
2 | const num = 102;
3 |
4 | // DO NOT TOUCH! (please)
5 | if (num <= 100) {
6 | if (num >= 50) {
7 | console.log("HEY!");
8 | }
9 | } else {
10 | if (num < 103) {
11 | if (num % 2 === 0) {
12 | console.log("YOU GOT ME!");
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/coding-exercise-24/solution/index.js:
--------------------------------------------------------------------------------
1 | const mystery = 'Panda7';
2 |
3 | // LEAVE THIS CODE ALONE! (pretty please)
4 | if(mystery[0] === 'P' && mystery.length > 5 && mystery.indexOf('7') !== -1){
5 | console.log("YOU GOT IT!!!");
6 | }
--------------------------------------------------------------------------------
/coding-exercise-25/solution/index.js:
--------------------------------------------------------------------------------
1 | // Define lottoNumbers below:
2 | const lottoNumbers = [45, 12, 23, 20, 9, 6];
--------------------------------------------------------------------------------
/coding-exercise-26/solution/index.js:
--------------------------------------------------------------------------------
1 | const leaderboard = ['Harry', 'Lua', 'Hermione', 'Bellatrix']; // DON'T TOUCH THIS LINE!
2 |
3 | // YOUR CODE BELOW HERE:
4 | leaderboard[1] = "Luna";
5 | leaderboard[3] = "Draco";
--------------------------------------------------------------------------------
/coding-exercise-27/solution/index.js:
--------------------------------------------------------------------------------
1 | const planets = ['The Moon', 'Venus', 'Earth', 'Mars', 'Jupiter']; // DO NOT TOUCH THIS LINE!
2 |
3 | // YOUR CODE GOES BELOW THIS LINE:
4 | planets.shift();
5 | planets.push('Saturn');
6 | planets.unshift('Mercury');
--------------------------------------------------------------------------------
/coding-exercise-28/solution/index.js:
--------------------------------------------------------------------------------
1 | // DO NOT TOUCH!!! (please)
2 | const airplaneSeats = [
3 | ['Ruth', 'Anthony', 'Stevie'],
4 | ['Amelia', 'Pedro', 'Maya'],
5 | ['Xavier', 'Ananya', 'Luis'],
6 | ['Luke', null, 'Deniz'],
7 | ['Rin', 'Sakura', 'Francisco']
8 | ]
9 |
10 | // YOUR CODE GOES BELOW THIS LINE:
11 | airplaneSeats[3][1] = 'Hugo';
--------------------------------------------------------------------------------
/coding-exercise-29/solution/index.js:
--------------------------------------------------------------------------------
1 | const product = {
2 | name: 'Gummy Bears',
3 | inStock: true,
4 | price: 1.99,
5 | flavors: ['cherry', 'orange', 'lemon']
6 | };
--------------------------------------------------------------------------------
/coding-exercise-30/solution/index.js:
--------------------------------------------------------------------------------
1 | // PLEASE DON'T TOUCH THIS LINE!
2 | const restaurant = {
3 | name: 'Ichiran Ramen',
4 | address: `${Math.floor(Math.random() * 100) + 1} Johnson Ave`,
5 | city: 'Brooklyn',
6 | state: 'NY',
7 | zipcode: '11206',
8 | };
9 |
10 | // YOUR CODE GOES DOWN HERE:
11 | const fullAddress = `${restaurant.address}, ${restaurant.city}, ${restaurant.state} ${restaurant.zipcode}`;
12 |
13 |
14 | // Alternative approaches:
15 | // #1:
16 | const fullAddress = `${restaurant["address"]}, ${restaurant["city"]}, ${restaurant["state"]} ${restaurant["zipcode"]}`;
17 | // #2:
18 | const fullAddress = restaurant.address + ", " + restaurant.city + ", " + restaurant.state + " " + restaurant.zipcode;
19 | // #3:
20 | const fullAddress = restaurant["address"] + ", " + restaurant["city"] + ", " + restaurant["state"] + " " + restaurant["zipcode"];
--------------------------------------------------------------------------------
/coding-exercise-31/solution/index.js:
--------------------------------------------------------------------------------
1 | // Print out "Da ba dee da ba daa" 6 times, using a for loop
2 | for (let i = 0; i < 6; i++) {
3 | console.log('Da ba dee da ba daa');
4 | }
--------------------------------------------------------------------------------
/coding-exercise-32/solution/index.js:
--------------------------------------------------------------------------------
1 | // Write a loop that prints:
2 | // 25
3 | // 20
4 | // 15
5 | // 10
6 | // 5
7 | // 0
8 |
9 | for (let i = 25; i >= 0; i -= 5) {
10 | console.log(i);
11 | }
--------------------------------------------------------------------------------
/coding-exercise-33/solution/index.js:
--------------------------------------------------------------------------------
1 | const people = ["Scooby", "Velma", "Daphne", "Shaggy", "Fred"]; // DON'T TOUCH THIS LINE!
2 |
3 | // WRITE YOUR LOOP BELOW THIS LINE:
4 | for (let i = 0; i < people.length; i++) {
5 | console.log(people[i].toUpperCase());
6 | }
--------------------------------------------------------------------------------
/coding-exercise-34/solution/index.js:
--------------------------------------------------------------------------------
1 | const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]; // DON'T CHANGE THIS LINE PLEASE!
2 |
3 | // WRITE YOUR LOOP BELOW THIS LINE:
4 | for (let num of numbers) {
5 | console.log(num * num);
6 | }
--------------------------------------------------------------------------------
/coding-exercise-35/solution/index.js:
--------------------------------------------------------------------------------
1 | function printHeart() {
2 | console.log('<3');
3 | }
4 |
5 | printHeart();
--------------------------------------------------------------------------------
/coding-exercise-36/solution-2/index.js:
--------------------------------------------------------------------------------
1 | function rant(message) {
2 | for (let i = 0; i < 3; i++) {
3 | console.log(message.toUpperCase());
4 | }
5 | }
--------------------------------------------------------------------------------
/coding-exercise-36/solution/index.js:
--------------------------------------------------------------------------------
1 | function rant(message) {
2 | console.log(message.toUpperCase());
3 | console.log(message.toUpperCase());
4 | console.log(message.toUpperCase());
5 | }
6 |
7 | // Solution with a for loop:
8 | function rant(message) {
9 | for (let i = 0; i < 3; i++) {
10 | console.log(message.toUpperCase());
11 | }
12 | }
--------------------------------------------------------------------------------
/coding-exercise-37/solution/index.js:
--------------------------------------------------------------------------------
1 | function isSnakeEyes(die1, die2) {
2 | if (die1 === 1 && die2 === 1) {
3 | console.log('Snake Eyes!');
4 | } else {
5 | console.log('Not Snake Eyes!');
6 | }
7 | }
--------------------------------------------------------------------------------
/coding-exercise-38/solution/index.js:
--------------------------------------------------------------------------------
1 | function multiply(num1, num2) {
2 | return num1 * num2;
3 | }
--------------------------------------------------------------------------------
/coding-exercise-39/solution/index.js:
--------------------------------------------------------------------------------
1 | function isShortsWeather(temperature) {
2 | return temperature >= 75;
3 | }
4 |
5 | // Other approaches:
6 |
7 | // Using an explicit if/else
8 | function isShortsWeather(temperature) {
9 | if (temperature >= 75) {
10 | return true;
11 | } else {
12 | return false;
13 | }
14 | }
15 |
16 | // Using the JavaScript ternary operator syntax
17 | function isShortsWeather(temperature) {
18 | return temperature >= 75 ? true : false;
19 | }
--------------------------------------------------------------------------------
/coding-exercise-40/solution-2/index.js:
--------------------------------------------------------------------------------
1 | function lastElement(arr) {
2 | if (!arr.length) {
3 | return null;
4 | }
5 | return arr[arr.length - 1];
6 | }
7 |
8 | // Or we can write it like this:
9 | function lastElement(arr) {
10 | if (!arr.length) return null;
11 | return arr[arr.length - 1];
12 | }
13 |
14 | // Another approach:
15 | function lastElement(arr) {
16 | if (arr.length > 0) {
17 | return arr[arr.length - 1];
18 | }
19 | return null;
20 | }
21 |
22 | function lastElement(arr) {
23 | if (arr.length > 0) return arr[arr.length - 1];
24 | return null;
25 | }
--------------------------------------------------------------------------------
/coding-exercise-40/solution-3/index.js:
--------------------------------------------------------------------------------
1 | // Using the JavaScript ternary operator syntax
2 | function lastElement(arr) {
3 | return arr.length > 0 ? arr[arr.length - 1] : null;
4 | }
5 |
6 | // Another approach:
7 | // arr.length will be 'truthy' if it's not 0, so we can write this:
8 | function lastElement(arr) {
9 | return arr.length ? arr[arr.length - 1] : null;
10 | }
--------------------------------------------------------------------------------
/coding-exercise-40/solution/index.js:
--------------------------------------------------------------------------------
1 | function lastElement(arr) {
2 | if (arr.length === 0) {
3 | return null;
4 | } else {
5 | return arr[arr.length - 1];
6 | }
7 | }
--------------------------------------------------------------------------------
/coding-exercise-41/solution-2/index.js:
--------------------------------------------------------------------------------
1 | // A bit more explicit solution:
2 | function capitalize(word) {
3 | const firstLetterCapitalized = word[0].toUpperCase();
4 | const restOfTheString = word.slice(1);
5 | return firstLetterCapitalized + restOfTheString;
6 | }
--------------------------------------------------------------------------------
/coding-exercise-41/solution/index.js:
--------------------------------------------------------------------------------
1 | function capitalize(word) {
2 | return word[0].toUpperCase() + word.slice(1);
3 | }
--------------------------------------------------------------------------------
/coding-exercise-42/solution-2/index.js:
--------------------------------------------------------------------------------
1 | function sumArray(nums) {
2 | let total = 0;
3 | for (let i = 0; i < nums.length; i++) {
4 | total += nums[i];
5 | }
6 | return total;
7 | }
--------------------------------------------------------------------------------
/coding-exercise-42/solution/index.js:
--------------------------------------------------------------------------------
1 | function sumArray(nums) {
2 | let total = 0;
3 | for (let num of nums) {
4 | total += num;
5 | }
6 | return total;
7 | }
--------------------------------------------------------------------------------
/coding-exercise-43/solution-2/index.js:
--------------------------------------------------------------------------------
1 | function returnDay(num) {
2 | if (num < 1 || num > 7) {
3 | return null;
4 | }
5 | const days = {
6 | 1: 'Monday',
7 | 2: 'Tuesday',
8 | 3: 'Wednesday',
9 | 4: 'Thursday',
10 | 5: 'Friday',
11 | 6: 'Saturday',
12 | 7: 'Sunday'
13 | };
14 | return days[num];
15 | }
--------------------------------------------------------------------------------
/coding-exercise-43/solution-3/index.js:
--------------------------------------------------------------------------------
1 | function returnDay(num) {
2 | const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
3 | const day = days[num - 1];
4 | // Using the JavaScript ternary operator syntax
5 | return day ? day : null;
6 | }
--------------------------------------------------------------------------------
/coding-exercise-43/solution-4/index.js:
--------------------------------------------------------------------------------
1 | // A long approach:
2 | function returnDay(num) {
3 | if (num < 1 || num > 7) {
4 | return null;
5 | } else if (num === 1) {
6 | return ('Monday');
7 | } else if (num === 2) {
8 | return ('Tuesday');
9 | } else if (num === 3) {
10 | return ('Wednesday');
11 | } else if (num === 4) {
12 | return ('Thursday');
13 | } else if (num === 5) {
14 | return ('Friday');
15 | } else if (num === 6) {
16 | return ('Saturday');
17 | } else if (num === 7) {
18 | return ('Sunday');
19 | }
20 | }
--------------------------------------------------------------------------------
/coding-exercise-43/solution-5/index.js:
--------------------------------------------------------------------------------
1 | // A long approach with a switch statement
2 | function returnDay(num) {
3 | if (num >= 1 || num <= 7) {
4 | switch (num) {
5 | case 1:
6 | return 'Monday';
7 | case 2:
8 | return 'Tuesday';
9 | case 3:
10 | return 'Wednesday';
11 | case 4:
12 | return 'Thursday';
13 | case 5:
14 | return 'Friday';
15 | case 6:
16 | return 'Saturday';
17 | case 7:
18 | return 'Sunday';
19 | default:
20 | return null;
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/coding-exercise-43/solution/index.js:
--------------------------------------------------------------------------------
1 | function returnDay(num) {
2 | const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
3 | if (num < 1 || num > 7) {
4 | return null;
5 | } else {
6 | return days[num - 1];
7 | }
8 | }
9 |
10 | // Another approach:
11 | function returnDay(num) {
12 | const days = [null, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
13 | if (num < 1 || num > 7) {
14 | return null;
15 | } else {
16 | return days[num];
17 | }
18 | }
19 |
20 | // Some more different approaches:
21 |
22 | function returnDay(num) {
23 | if (num < 1 || num > 7) {
24 | return null;
25 | }
26 | const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
27 | return days[num - 1];
28 | }
29 |
30 | function returnDay(num) {
31 | if (num >= 1 && num <= 7) {
32 | const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
33 | return days[num - 1];
34 | }
35 | return null;
36 | }
--------------------------------------------------------------------------------
/coding-exercise-44/solution/index.js:
--------------------------------------------------------------------------------
1 | const square = function (num) {
2 | return num * num;
3 | }
4 |
5 | // More approaches:
6 |
7 | // #2
8 | const square = function (num) {
9 | return Math.pow(num, 2);
10 | }
11 |
12 | // #3 (doesn't work on the Udemy coding exercise platform at the time of writing this)
13 | const square = function (num) {
14 | return num ** 2;
15 | }
--------------------------------------------------------------------------------
/coding-exercise-45/solution/index.js:
--------------------------------------------------------------------------------
1 | const square = {
2 | area(side) {
3 | return side * side;
4 | },
5 | perimeter(side) {
6 | return side * 4;
7 | }
8 | }
9 |
10 | // More verbose syntax approach:
11 | const square = {
12 | area: function (side) {
13 | return side * side;
14 | },
15 | perimeter: function (side) {
16 | return side * 4;
17 | }
18 | }
--------------------------------------------------------------------------------
/coding-exercise-46/solution/index.js:
--------------------------------------------------------------------------------
1 | const hen = {
2 | name: 'Helen',
3 | eggCount: 0,
4 | layAnEgg() {
5 | this.eggCount++;
6 | return 'EGG';
7 | }
8 | };
9 |
10 | // A bit more verbose:
11 | const hen = {
12 | name: 'Helen',
13 | eggCount: 0,
14 | layAnEgg: function () {
15 | this.eggCount += 1;
16 | return 'EGG';
17 | }
18 | };
--------------------------------------------------------------------------------
/coding-exercise-47/solution/index.js:
--------------------------------------------------------------------------------
1 | // DO NOT ALTER THE FOLLOWING CODE:
2 | const fullNames = [{first: 'Albus', last: 'Dumbledore'}, {first: 'Harry', last: 'Potter'}, {
3 | first: 'Hermione',
4 | last: 'Granger'
5 | }, {first: 'Ron', last: 'Weasley'}, {first: 'Rubeus', last: 'Hagrid'}, {
6 | first: 'Minerva',
7 | last: 'McGonagall'
8 | }, {first: 'Severus', last: 'Snape'}];
9 |
10 | // Write your code here
11 | const firstNames = fullNames.map(function (name) {
12 | return name.first;
13 | });
14 |
15 | // Arrow function syntax approach:
16 | const firstNames = fullNames.map(name => name.first);
--------------------------------------------------------------------------------
/coding-exercise-48/solution/index.js:
--------------------------------------------------------------------------------
1 | const greet = (name) => {
2 | return `Hey ${name}!`;
3 | }
4 |
5 | // More concise approach:
6 | const greet = name => `Hey ${name}!`;
--------------------------------------------------------------------------------
/coding-exercise-49/solution/index.js:
--------------------------------------------------------------------------------
1 | function validUserNames(arr) {
2 | const filteredArr = arr.filter(function (name) {
3 | return name.length < 10;
4 | });
5 | return filteredArr;
6 | }
7 |
8 | // Another approach:
9 | function validUserNames(arr) {
10 | return arr.filter(name => name.length < 10);
11 | }
12 |
13 | // Concise full arrow function syntax approach:
14 | const validUserNames = usernames => usernames.filter(usr => usr.length < 10);
--------------------------------------------------------------------------------
/coding-exercise-50/solution/index.js:
--------------------------------------------------------------------------------
1 | function allEvens(arr) {
2 | return arr.every(function (num) {
3 | return num % 2 === 0;
4 | });
5 | }
6 |
7 | // Another approach:
8 | const allEvens = function (arr) {
9 | return arr.every(num => num % 2 === 0);
10 | }
11 |
12 | // Concise full arrow function syntax approach:
13 | const allEvens = arr => arr.every(num => num % 2 === 0);
--------------------------------------------------------------------------------
/coding-exercise-51/solution/app.js:
--------------------------------------------------------------------------------
1 | // Write your code in here:
2 | const image = document.getElementById('unicorn');
3 | const heading = document.getElementById('mainheading');
--------------------------------------------------------------------------------
/coding-exercise-51/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Unicorn
8 |
9 |
10 | I ♥ unicorns
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/coding-exercise-52/solution/app.css:
--------------------------------------------------------------------------------
1 | /* No need to change anything in here! */
2 | .done {
3 | color: grey;
4 | text-decoration: line-through;
5 | }
--------------------------------------------------------------------------------
/coding-exercise-52/solution/app.js:
--------------------------------------------------------------------------------
1 | // Your code goes in here:
2 | const doneTodos = document.querySelectorAll('.done');
3 | const checkbox = document.querySelector('input[type="checkbox"]');
--------------------------------------------------------------------------------
/coding-exercise-52/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Todos
6 |
7 |
8 |
9 |
10 | Garden Todos
11 |
12 |
13 | Start Seedlings
14 | Deadhead Zinnias
15 | Water Tomatoes
16 | Harvest Potatoes
17 | Prune Roses
18 |
19 | Delete All
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/coding-exercise-53/solution/app.js:
--------------------------------------------------------------------------------
1 | // YOUR CODE GOES IN HERE:
2 | const span = document.querySelector("span");
3 | span.innerText = 'Disgusting';
--------------------------------------------------------------------------------
/coding-exercise-53/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Pickles
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | Pickles Are Delicious
14 |
15 |
16 |