Skip to content
Snippets Groups Projects
Commit 63f45415 authored by Andrej Rasevic's avatar Andrej Rasevic
Browse files

adding lecture example from Wednesday

parent f8442584
No related branches found
No related tags found
No related merge requests found
console.log('hi')
\ No newline at end of file
{
"name": "demonodeapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
let sharedAdd = require('./functions').myAdd
console.log(sharedAdd(1,4))
\ No newline at end of file
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
<!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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment