From 63f454158c068dbf728b4995ace9a7401629d232 Mon Sep 17 00:00:00 2001
From: Andrej Rasevic <andrej@rasevicengineering.com>
Date: Thu, 23 Jun 2022 14:26:04 -0400
Subject: [PATCH] adding lecture example from Wednesday

---
 lectureExamples/demoNodeApp/hello.js     |  1 +
 lectureExamples/demoNodeApp/package.json | 11 ++++++
 lectureExamples/driver.js                |  4 ++
 lectureExamples/functions.js             | 10 +++++
 lectureExamples/newFetch.html            | 48 ++++++++++++++++++++++++
 5 files changed, 74 insertions(+)
 create mode 100644 lectureExamples/demoNodeApp/hello.js
 create mode 100644 lectureExamples/demoNodeApp/package.json
 create mode 100644 lectureExamples/driver.js
 create mode 100644 lectureExamples/functions.js
 create mode 100644 lectureExamples/newFetch.html

diff --git a/lectureExamples/demoNodeApp/hello.js b/lectureExamples/demoNodeApp/hello.js
new file mode 100644
index 0000000..309af59
--- /dev/null
+++ b/lectureExamples/demoNodeApp/hello.js
@@ -0,0 +1 @@
+console.log('hi')
\ No newline at end of file
diff --git a/lectureExamples/demoNodeApp/package.json b/lectureExamples/demoNodeApp/package.json
new file mode 100644
index 0000000..7a86a3a
--- /dev/null
+++ b/lectureExamples/demoNodeApp/package.json
@@ -0,0 +1,11 @@
+{
+  "name": "demonodeapp",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC"
+}
diff --git a/lectureExamples/driver.js b/lectureExamples/driver.js
new file mode 100644
index 0000000..e13dc90
--- /dev/null
+++ b/lectureExamples/driver.js
@@ -0,0 +1,4 @@
+let sharedAdd = require('./functions').myAdd
+
+
+console.log(sharedAdd(1,4))
\ No newline at end of file
diff --git a/lectureExamples/functions.js b/lectureExamples/functions.js
new file mode 100644
index 0000000..9ddc9ab
--- /dev/null
+++ b/lectureExamples/functions.js
@@ -0,0 +1,10 @@
+function myAdd(num1, num2) {
+    return num1 + num2
+}
+
+function mySubtract(num1, num2) {
+    return num1 - num2
+}
+
+module.exports.myAdd = myAdd
+module.exports.mySubtract = mySubtract
\ No newline at end of file
diff --git a/lectureExamples/newFetch.html b/lectureExamples/newFetch.html
new file mode 100644
index 0000000..aa9e090
--- /dev/null
+++ b/lectureExamples/newFetch.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <title>Fetch and Promises</title>
+    <meta charset="utf-8" />
+</head>
+
+<body>
+    <script>
+        
+        let url = "https://jsonplaceholder.typicode.com/todos/1"; // Notice the 1 at the end
+        
+        let data = {
+					"userId": 1,  
+					"id": 1,
+					"title": "delectus aut autem",
+					"completed": false
+				}
+				console.log(data)
+				console.log(JSON.stringify(data))
+        // This is going to mock what happens when we call the real Fetch API
+
+        function newFetch(data2) {
+					return new Promise((resolve, reject) => {
+            setTimeout(() => {
+              if (data2 === null) {
+                reject("Object is null")
+              }
+              resolve(data2)
+            }, 3000)
+					})
+        }
+
+				let result = newFetch(data)
+
+
+				newFetch(data)
+				 	.then(result => {
+            console.log('printing from newFetch')
+						console.log(result)
+          })
+				 	.catch(err => console.error(err))
+            
+    </script>
+</body>
+
+</html>
\ No newline at end of file
-- 
GitLab