This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The 'click' event which listens for a click. | |
document.getElementById('btn').addEventListener("click", turnThirdDivBlue); | |
// the function called as a callback above. | |
function turnThirdDivBlue() { | |
document.getElementById("thirdDiv").style.background = 'blue'; | |
document.getElementById('btn').innerHTML = "Turned blue on click!" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset = "UTF-8"/> | |
<link rel="stylesheet" href="style.css"> | |
</head> | |
<body> | |
<!-- the three divs --> | |
<div id="firstDiv" class='divs'></div> | |
<div id="secondDiv" class='divs'></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); // required for all steps. | |
// STEP #1 Basic server: | |
http.createServer(function(request,response) { | |
response.writeHead(200); // Tell the client if response is good. | |
response.write('My server worked!'); // the response body | |
response.end(); // end the connection. | |
}).listen(3000); // you can change this to another port if you want, but then you would have to visit that port in the browser too. | |
// STEP #1.5 Basic Server Continued... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// non-blocking / async code: | |
var fs = require('fs'); | |
console.log('ALERT: Escape from bunny prison!'); | |
// notice the method is called readFile not readFileSync. | |
fs.readFile('wishlist.html', function(err, wishlist) { | |
if(err) throw err; | |
console.log(wishlist.toString()); | |
}) | |
console.log('ALERT: Pounce owner!'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// blocking / sync code: | |
// you have to require the file system(fs), Node.js's core module for it to work: | |
var fs = require('fs'); | |
// First read the file 'wishlist.html' synchronously using the readFileSync method: | |
// We have to use the toString because it returns as a buffer. | |
// You can learn about buffers in the resources I provide at the end of this article. | |
var wishlist = fs.readFileSync('wishlist.html').toString(); | |
//print the file | |
console.log(wishlist); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Things I will pamper Brigadier Fluffykins with: | |
1. Carrot Bits | |
2. Lettuce Bits | |
3. Rasberry Bits | |
4. Toys | |
5. Hugs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bunny { | |
constructor(name, age, favoriteFood){ | |
this.name = name; | |
this.age = age; | |
this.favoriteFood = favoriteFood; | |
} | |
eatFavFood() { | |
console.log(`"Mmmm! That ${this.favoriteFood} was delicious", said ${this.name} the ${this.age} year old bunny.`); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// anonymous: | |
const Bunny = class { | |
etc... | |
}; | |
const BunnyBurgerKins = new Bunny(); | |
// named | |
const Bunny = class SurferBunny { | |
whatIsMyName() { | |
return SurferBunny.name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createNewBunny() { new Bunny(); } | |
createNewBunny(); // ReferenceError | |
class Bunny {...etc} | |
createNewBunny(); // Works! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Normal function declaration | |
// called before it is declared and it works. | |
callMe(); // Testing, Testing. | |
function callMe() { | |
console.log("Testing, Testing.") | |
} | |
// This is called after, as we would do in a function expression, | |
// and it works too! |