Skip to content

Commit a887ad4

Browse files
committed
clear student files and add css file
1 parent 16eaf0f commit a887ad4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2399
-41
lines changed

0-student_files/index.js

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +0,0 @@
1-
const http = require('http')
2-
const fs = require('fs');
3-
const PORT = 7000;
4-
5-
const HtmlTemplateString = (header,body,footer) => {
6-
return `<!DOCTYPE html>
7-
<html lang="en">
8-
<head>
9-
<meta charset="UTF-8">
10-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
11-
${header}
12-
</head>
13-
<body>
14-
${body}
15-
${footer}
16-
</body>
17-
</html>`;
18-
}
19-
let page1 = HtmlTemplateString(`<title>Title</title>`,`<h1>Hello World END</h1>`,`<footer> Content about the </footer>`);
20-
21-
// let page1 =HtmlTemplateString(
22-
// `<title>Hello</title>`,
23-
// `<h1>Hello World END</h1>
24-
// <div>Content about the world</div>`,
25-
// `<footer> By Hans </footer>`)
26-
27-
http.createServer(
28-
(request,res)=>{
29-
if (request.url == '/') {
30-
res.writeHead(200, {
31-
'Content-Type': 'text/html',
32-
'Content-Length': page1.length,
33-
// 'Expires': new Date().toUTCString()
34-
})
35-
res.end(page1);
36-
}
37-
}
38-
).listen(PORT);

0-student_files/style.css

Whitespace-only changes.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Resources:
3+
* 1. https://flaviocopes.com/javascript-iife/
4+
* 2. https://stackabuse.com/javascripts-immediately-invoked-function-expressions/
5+
* 3. https://medium.com/@vvkchandra/essential-javascript-mastering-immediately-invoked-function-expressions-67791338ddc6
6+
*/
7+
8+
9+
10+
( // open IIFE
11+
// Inner Anonymous Function
12+
function () {
13+
var tmp = "something";
14+
console.log(tmp);
15+
return tmp;
16+
}
17+
() // p
18+
); // close IIFE
19+
20+
21+
/**
22+
** Passing Data
23+
*/
24+
( // open IIFE
25+
26+
// Inner Anonymous Function
27+
function (data) {
28+
29+
var tmp = data; // not a global variable
30+
console.log(tmp);
31+
}
32+
("something else")
33+
); // close IIFE
34+
35+
// Arrow function
36+
(() => {
37+
/* */
38+
})()
39+
40+
41+
/**
42+
* with unary operators
43+
*/
44+
45+
+function () {
46+
// Code that runs in your function
47+
console.log("+");
48+
}();
49+
50+
-function () {
51+
// Code that runs in your function
52+
console.log("-");
53+
}();
54+
55+
!function () {
56+
console.log("!");
57+
// Code that runs in your function
58+
}();
59+
60+
~function () {
61+
// Code that runs in your function
62+
console.log("~");
63+
}();
64+
65+
void function () {
66+
// Code that runs in your function
67+
console.log("void");
68+
}();
69+
70+
71+
72+
for (var i = 1; i <= 5; i++) {
73+
(function (step) {
74+
setTimeout(
75+
() => console.log(`I reached step ${step}`),
76+
100 * i
77+
);
78+
})(i);
79+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function (param1, param2) {
2+
return param1 + param2;
3+
};
4+
console.log("something")
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
let singleParam = parameter => console.log(parameter);
2+
let multiParam = (parameter,parameter2) => console.log(parameter,parameter2);
3+
let mutlilineArrow = (parameters)=>{
4+
console.log(parameters)
5+
};
6+
7+
/**
8+
9+
---
10+
11+
### Arrow Functions
12+
13+
```javascript
14+
let singleParam = parameter => console.log(parameter);
15+
let multiParam = (parameter,parameter2) => console.log(parameter,parameter2);
16+
let mutlilineArrow = (parameters)=>{
17+
console.log(parameters)
18+
};
19+
```
20+
21+
{.fragment .current-only data-code-focus=1-1 }
22+
23+
{.fragment .current-only data-code-focus=2-2 }
24+
25+
{.fragment .current-only data-code-focus=3-3 }
26+
27+
{.fragment .current-only data-code-focus=4-4 }
28+
29+
{.fragment .current-only data-code-focus=5-5 }
30+
31+
32+
33+
34+
35+
---
36+
37+
38+
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
3+
function closureScoped(job) {
4+
if (job=="designer") {
5+
return (name)=>console.log(`my name is ${name} my job is ${job}`)
6+
}
7+
else if (job=="teacher") {
8+
return (name)=>console.log(`my name is ${name} my job is ${job}`)
9+
}
10+
else {
11+
return (name)=>console.log(`my name is ${name} my job is ${job}`)
12+
}
13+
}
14+
closureScoped("designer")("hans");
15+
16+
function curryingClosure(job){
17+
return function(name) {
18+
if (job=="Teacher")
19+
console.log(` ${name} can you explain closures? ${job}`)
20+
else if (job=="javaScripter")
21+
console.log(`${name} can explain closure and currying because he is a ${job}`)
22+
else
23+
console.log(`${name} what is your malfunction?`)
24+
}
25+
}
26+
27+
curryingClosure("javaScripter")("hans")
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
** function
3+
*/
4+
function firstFunction(params) {
5+
console.log("hello " + params);
6+
}
7+
firstFunction("hello")
8+
9+
/**
10+
** Arrow functions
11+
*/
12+
// single line
13+
() => console.log("single");
14+
// multiline
15+
() => {
16+
console.log("multiline");
17+
}
18+
// named arrow function
19+
const name = (params) => {
20+
console.log(params,"named");
21+
}
22+
23+
/**
24+
** Immediately Invoked Function Expressions (IFFY)
25+
* http://adripofjavascript.com/blog/drips/an-introduction-to-iffes-immediately-invoked-function-expressions.html
26+
*/
27+
(function () {
28+
var foo = "bar";
29+
30+
// Outputs: "bar"
31+
console.log(foo);
32+
})();
33+
34+
// ReferenceError: foo is not defined
35+
console.log(foo);
36+
37+
/**
38+
** Event Loop
39+
* 1. Arrays & Memory Heap
40+
* 2. Stack
41+
* 3. Queue
42+
* 4. Call Stack & Callback Queue
43+
* https://blog.sessionstack.com/how-javascript-works-event-loop-and-the-rise-of-async-programming-5-ways-to-better-coding-with-2f077c4438b5
44+
*
45+
*/
46+
47+
48+
/**
49+
** Asynchronous Code
50+
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous
51+
* 1. Callbacks
52+
* 2. Promises
53+
* 3. Async/Await
54+
* 4. Async Generators
55+
*/
56+
57+
/**
58+
** callbacks
59+
https://www.dashingd3js.com/lessons/javascript-callback-functions
60+
*/
61+
function callback(x) {
62+
console.log(x);
63+
}
64+
function callbackFunction(var1, var2, callback1, callback2) {
65+
callback1(var1);
66+
callback2(var2);
67+
}
68+
69+
callbackFunction( 1, 2, // var1, var2
70+
function (x) { console.log(x); }, // callback1
71+
function (x) { console.log(x); } // callback2
72+
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function getRectArea(width, height) {
2+
if (width > 0 && height > 0) {
3+
console.log(width * height)
4+
return width * height;
5+
}
6+
console.log(0)
7+
return 0;
8+
}
9+
10+
11+
getRectArea(3, 4) // 12
12+
getRectArea(-3, 4) // 0
13+
// console.log(getRectArea(3, 4)); // 12
14+
// console.log(getRectArea(-3, 4)); // 0
113 KB
Loading
164 KB
Loading

0 commit comments

Comments
 (0)