Skip to content

Commit 55a8ea8

Browse files
committed
Rewrite hype
I'm doing this. It's happening. Let's go.
1 parent 692b4af commit 55a8ea8

File tree

24 files changed

+182
-111
lines changed

24 files changed

+182
-111
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
trim_trailing_whitespace = true
7+
end_of_line = lf
8+
insert_final_newline = true
9+
10+
[*.md]
11+
indent_size = 4
12+
trim_trailing_whitespace = false
13+

exercises/01 - JavaScript Drum Kit/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Exercise 1: JavaScript Drum Kit
22
Nitish Dayal, Software & Applications Developer - [Contact](http://nitishdayal.me)
3-
Last Commit Date: Dec 9, 2016
3+
Last Commit Date: May 12, 2017
44

55
An HTML page displays a collection of `div` elements, each containing a letter
66
that corresponds with a key on the keyboard, and the name of the soundclip to be
77
played when that button is clicked. When a user presses a key that matches
8-
one of the `div` elements, the page should play the corresponding soundclip
9-
and place a temporary 'highlight' (or border) around the `div`. Write the
10-
JavaScript code necessary to add this functionality.
8+
one of the letters displayed in the `div` elements, the page should play
9+
the corresponding soundclip and place a temporary 'highlight' (or border)
10+
around the `div`. Write the JavaScript code necessary to add this functionality.
1111

1212
## Guide
1313

@@ -17,11 +17,11 @@ We are provided with the HTML, CSS, and sound clips necessary to create this
1717

1818
- HTML `data-*` attributes: Introduced in HTML5, `data-*` attributes (where * can
1919
be anything you want) allow us to store _custom data_ on any HTML element. Each
20-
`div.key` and `audio` element in the provided HTML file has a `data-key` attribute
21-
which corresponds with a keyboard button.
20+
`div.key` (`<div class="key" data-key="...">`) and `audio` element in the
21+
provided HTML file has a `data-key` attribute which corresponds with a keyboard button.
2222

23-
- CSS `playing` class & pre-defined style: The provided CSS file already has an `playing`
24-
class defined with some styling in it. We will apply this class to the correct
23+
- CSS `playing` class & pre-defined style: The provided CSS file already has a `playing`
24+
class defined with some rules in it. We will apply this class to the correct
2525
element, depending on the key pressed by the user, and remove it once animation
2626
is finished.
2727

exercises/01 - JavaScript Drum Kit/index.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
* and then remove that class in order to reset the element to it's original state.
6767
*/
6868

69-
(function () {
69+
(()=> {
7070
const playSound = (e) => {
7171
const soundclip = document.querySelector(`audio[data-key="${e.keyCode}"]`);
7272
const keyelement = document.querySelector(`.key[data-key="${e.keyCode}"]`);
@@ -75,9 +75,9 @@
7575

7676
keyelement.classList.add('playing');
7777

78-
soundclip.currentTime = 0; // Play sound
78+
soundclip.currentTime = 0;
7979

80-
soundclip.play();
80+
soundclip.play(); // Play sound
8181
}
8282

8383
const removeTransition = (e) => {
@@ -95,8 +95,7 @@
9595
key.addEventListener(
9696
'transitionend',
9797
(e) => removeTransition.call(key, e)
98-
)
99-
);
98+
));
10099
})();
101100
</script>
102101

Lines changed: 90 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,101 @@
11
# Exercise 2: JS + CSS Clock
2-
Nitish Dayal, Software & Applications Developer - [Contact](http://nitishdayal.me)
3-
Last Commit Date: Dec 9, 2016
42

5-
Given an web page with an analog clock created out of CSS, update the CSS
6-
and write the JavaScript necessary to make the clock functional.
3+
> Nitish Dayal, Software & Applications Developer - [Contact](http://nitishdayal.me)
4+
> Last Commit Date: May 12, 2017
5+
6+
Given a web page with an analog clock created with CSS, write the
7+
JavaScript necessary to make the clock functional. Make alterations to the CSS
8+
as necessary.
79

810
## Guide
911

1012
The HTML file has 3 `div` elements which correspond with the second, minute, and
11-
hour hand on a clock. We'll create references to these elements and dynamically
12-
update certain CSS properties to change their positions so they reflect the
13-
current time. Easy peasy.
13+
hour hand on a clock
14+
15+
```html
16+
<!-- ...previous elements -->
17+
<div class="hand hour-hand"></div>
18+
<div class="hand min-hand"></div>
19+
<div class="hand second-hand"></div>
20+
<!-- next elements... -->
21+
```
22+
23+
The necessary JavaScript code shouldn't be too crazy;
24+
we'll create references to these elements and dynamically
25+
update certain CSS properties to change their positions so they reflect the
26+
current time. Easy peasy.
1427

1528
**Steps:**
1629

17-
- CSS:
18-
19-
1. Set the `transform-origin` CSS property of the `.hand` class at 100%; the default
20-
value is 50% (or the midway point of the HTML element), but if we leave it there
21-
the clock hands will tranform from their individal centers as opposed to the
22-
center of the clock. Changing the value to 100% shifts the _origin point of the
23-
transformations_ to the furthest x-axis point of the HTML element.
24-
2. The hands are all laying flat; we need them to be vertical. Rotate all of the
25-
hands by 90 degrees so that they are upright.
26-
3. Set the `transition` CSS property of `.hand` to `all 0.05s`; this tells the browser
27-
to gradually apply any changes to the element's styling over a 0.05 second period.
28-
4. Set the `transition-timing-function` CSS property of `.hand` to whatever function
29-
you prefer, or define your own using the `cubic-bezier()` property value.
30-
31-
- JavaScript
32-
33-
1. Declare & define variables for each clock hand and reference the corresponding _HTML
34-
element_.
35-
2. Create a function which will be responsible for updating the position of all the
36-
clock hands.
37-
- Calculate the necessary rotation using the _current numerical time value_ for each hand
38-
and dividing it by the max value possible to get the percentage, multiplying the result
39-
of that by 360 (each hand can rotate 360 degrees) to get the numerical value for the
40-
rotation, and increasing that by another 90 degrees to compensate for the shift
41-
originally applied by the CSS styling on page load.
42-
3. Call the function defined in step 2 every second.
30+
- **CSS**:
31+
32+
1. The hands are all laying flat; we need them to be vertical. Rotate all of the
33+
hands by 90 degrees so that they are upright by giving the `.hand` class a
34+
`transform` rule with the value `rotate(90deg)`.
35+
36+
1. Set the `transform-origin` CSS property of the `.hand` class to `100%`; the default
37+
value is `50%` (or the midway point of the HTML element), but if we leave it there
38+
the clock hands will transform from the respective centers of their lines as opposed to the
39+
center of the clock. (If that doesn't make sense, try it out in your code. Set the value for
40+
`transform-origin` rule completely and check again. Finally, try it again with `50%`.).
41+
Changing the value to 100% shifts the _point of origin for the transformation_
42+
to the furthest point on the x-axis of the HTML element.
43+
44+
1. Set the `transition` CSS property of `.hand` to `all 0.05s`; this tells the browser
45+
to gradually apply any changes to the element's styling over a 0.05 second period.
46+
47+
1. Set the `transition-timing-function` CSS property of `.hand` to whatever function
48+
you prefer, or define your own using the `cubic-bezier()` property value.
49+
50+
- **JavaScript**:
51+
52+
1. Declare & define variables for each clock hand and reference the corresponding _HTML
53+
element_.
54+
55+
EX: `const secondHand = document.querySelector('.second-hand');`
56+
57+
1. Create a function which will be responsible for calculating the number of degrees that we need
58+
to rotate each clock hand by. It should accept two arguments: the _current numerical value_ of the
59+
clock hand, and the max value possible of the clock hand (if you want the number of degrees needed for
60+
the second hand and the current time is 03:15:18, you would pass in (18, 60) where 18 is the current
61+
value of the second hand, and 60 is the maximum possible value).
62+
63+
- Divide the current numerical value of the clock hand by it's max possible value to get the rotation as
64+
a percentage, then multiply the result of that by 360 (each hand can rotate 360 degrees) to convert
65+
the value from a percentage to an integer, and increase that result by another 90 degrees to compensate
66+
for the shift originally applied by the CSS styling on page load.
67+
68+
```javascript
69+
const calcDegrees = (time, max) => ((time / max) * 360) + 90;
70+
```
71+
72+
1. Create a function that will automatically run every second; in the body of the function,
73+
create a variable and define it as a new Date object. Then, create three variables which will
74+
hold references to the rotation amount to be applied to each clock hand. To get the rotation amount,
75+
define the variables as the return value from calling the `calcDegrees` function; each call should
76+
pass in the correct values in relation to whichever clock hand they are supposed to represent.
77+
78+
1. Still within the body of the function from step 3, update the `transform` rule for each
79+
clock hand to their corresponding updated values.
80+
81+
```javascript
82+
/* Steps 3 & 4 */
83+
84+
// Call function once every second
85+
setInterval(() => {
86+
// Create new Date object
87+
const now = new Date();
88+
// Get current seconds, minutes, & hours and calculate the degree shift
89+
const
90+
secondHandDegrees = calcDegrees(now.getSeconds(), 60),
91+
minuteHandDegrees = calcDegrees(now.getMinutes(), 60),
92+
hourHandDegrees = calcDegrees(now.getHours(), 12);
93+
// Apply rotation to the clock hands corresponding with current time value
94+
secondHand.style.transform = `rotate(${secondHandDegrees}deg)`;
95+
minuteHand.style.transform = `rotate(${minuteHandDegrees}deg)`;
96+
hourHand.style.transform = `rotate(${hourHandDegrees}deg)`;
97+
}, 1000); // 1000ms === 1s
98+
99+
```
43100

44101
Yaaaaaay! All done!

exercises/02 - JS + CSS Clock/index.html

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
text-align: center;
2626
font-size: 10px;
2727
}
28-
28+
2929
body {
3030
font-size: 2rem;
3131
display: flex;
3232
flex: 1;
3333
min-height: 100vh;
3434
align-items: center;
3535
}
36-
36+
3737
.clock {
3838
width: 30rem;
3939
height: 30rem;
@@ -44,15 +44,15 @@
4444
padding: 2rem;
4545
box-shadow: 0 0 0px 4px rgba(0, 0, 0, 0.1), inset 0 0 0 3px #EFEFEF, inset 0 0 10px black, 0 0 10px rgba(0, 0, 0, 0.2);
4646
}
47-
47+
4848
.clock-face {
4949
position: relative;
5050
width: 100%;
5151
height: 100%;
5252
transform: translateY(-3px);
5353
/* account for the height of the clock hands */
5454
}
55-
55+
5656
.hand {
5757
width: 50%;
5858
height: 6px;
@@ -73,13 +73,16 @@
7373
*/
7474

7575
// Create references to the HTML elements that we want to transform
76-
const
77-
secondHand = document.querySelector('.second-hand'),
78-
minuteHand = document.querySelector('.min-hand'),
79-
hourHand = document.querySelector('.hour-hand')
80-
const calcDegrees = (int, div) => ((int / div) * 360) + 90;
81-
// Call function once every second
82-
setInterval(() => {
76+
(()=> {
77+
const
78+
secondHand = document.querySelector('.second-hand'),
79+
minuteHand = document.querySelector('.min-hand'),
80+
hourHand = document.querySelector('.hour-hand')
81+
82+
// Helper function responsible for calculating the amount to rotate a hand
83+
const calcDegrees = (time, max) => ((time / max) * 360) + 90;
84+
// Call function once every second
85+
setInterval(() => {
8386

8487
// Create new Date object
8588
const now = new Date();
@@ -90,14 +93,12 @@
9093
minuteHandDegrees = calcDegrees(now.getMinutes(), 60),
9194
hourHandDegrees = calcDegrees(now.getHours(), 12);
9295

93-
9496
// Apply rotation to the clock hands corresponding with current time value
9597
secondHand.style.transform = `rotate(${secondHandDegrees}deg)`;
9698
minuteHand.style.transform = `rotate(${minuteHandDegrees}deg)`;
9799
hourHand.style.transform = `rotate(${hourHandDegrees}deg)`;
98-
99-
100100
}, 1000);
101+
})();
101102
</script>
102103
</body>
103104

exercises/03 - CSS Variables/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Exercise 3: CSS Variables
22
Nitish Dayal, Software & Applications Developer - [Contact](http://nitishdayal.me)
3-
Last Commit Date: Dec 10, 2016
3+
Last Commit Date: May 12, 2017
44

55
The web page provided in this exercise displays an image, and has 3 form inputs
66
from which the user can manipulate the padding, blur amount, and background

exercises/04 - Array Cardio Day 1/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Exercise 4: Array Cardio
22
Nitish Dayal, Software & Applications Developer - [Contact](http://nitishdayal.me)
3-
Last Commit Date: Dec 12, 2016
3+
Last Commit Date: May 12, 2017
44

55
Not really much of a guide necessary for this one. The challenge is pretty
66
well documented as far as what's expected from the developer; use

exercises/05 - Flex Panel Gallery/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Exercise 5: Flex Panel Gallery
22
Nitish Dayal, Software & Applications Developer - [Contact](http://nitishdayal.me)
3-
Last Commit Date: Dec 12, 2016
3+
Last Commit Date: May 12, 2017
44

55
We are given a web page with five `div` HTML elements with a class `panels`,
66
each containing three `p` HTML elements with some text. These five `div` elements

exercises/06 - Type Ahead/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Exercise 6: Type Ahead AJAX
22
Nitish Dayal, Software & Applications Developer - [Contact](http://nitishdayal.me)
3-
Last Commit Date: Dec 12, 2016
3+
Last Commit Date: May 12, 2017
44

55
We are given a web page with an `input` HTML element in which the user can insert
66
text, and an `unordered list` below that `input` which will display cities & states

exercises/07 - Array Cardio Day 2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Exercise 7: Array Cardio Day 2
22
Nitish Dayal, Software & Applications Developer - [Contact](http://nitishdayal.me)
3-
Last Commit Date: Dec 12, 2016
3+
Last Commit Date: May 12, 2017
44

55
More fun with Array methods! Much like the previous Array Cardio exercise, the
66
requirements are pretty well documented. This exercise utilizes the following

0 commit comments

Comments
 (0)