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 convertToC(fahrenheit) { | |
var celsius; | |
celsius = parseFloat((fahrenheit - 32) * 5/9).toFixed(2); | |
return celsius; | |
} |
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 convertToF(celsius) { | |
var fahrenheit; | |
fahrenheit = parseInt(celsius*9/5 + 32); | |
return fahrenheit; | |
} |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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 talksAbout(node, string) { | |
if (node.nodeType == document.ELEMENT_NODE) { | |
for (var i = 0; i < node.childNodes.length; i++) { | |
if (talksAbout(node.childNodes[i], string)) | |
return true; | |
} | |
return false; | |
} else if (node.nodeType == document.TEXT_NODE) { | |
return node.nodeValue.indexOf(string) > -1; | |
} |
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 board= "" | |
function chessboard(size){ | |
for (var i = 0; i < size; i++) { // 8 rows | |
if (i%2==0) { | |
for (var j = 0; j < size; j++) { // 8 columns | |
if (j%2 ==0) { | |
board+=" " | |
} else { | |
board+="#" |
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
// This can be useful to reveal "hidden" properties (properties in the prototype chain which are not accessible through the object, because another property has the same name earlier in the prototype chain). Listing accessible properties only can easily be done by removing duplicates in the array. | |
function listAllProperties(o) { | |
var objectToInspect; | |
var result = []; | |
for(objectToInspect = o; objectToInspect !== null; objectToInspect = Object.getPrototypeOf(objectToInspect)){ | |
result = result.concat(Object.getOwnPropertyNames(objectToInspect)); | |
} | |
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 StaffMember(employee,discountPercent){ | |
this.employee = employee; | |
this.discountPercent = discountPercent; | |
} | |
var sally = new StaffMember("Sally",5); | |
var bob = new StaffMember("Bob",10); | |
// Create yourself again as 'me' with a staff discount of 20% | |
var me = new StaffMember("Sean",20); |
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 user = prompt("Pick a number between 1 and 3").toUpperCase(); | |
switch(user){ | |
case '1': | |
if(user === '1' && !isNaN(user)){ | |
console.log("don't you want more?"); | |
break; | |
} else { | |
user = prompt("Try again"); | |
} |
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 slaying= true; | |
var youHit = Math.floor(Math.random() * 2); | |
var damageThisRound = Math.floor(Math.random() * 5 + 1); | |
var totalDamage = 0; | |
while (slaying) { | |
totalDamage += damageThisRound; | |
if (youHit == 1) { | |
slaying=false; | |
if (totalDamage >= 4) { |
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
pre-vetted ES6 polyfills { | |
ES5-Shim | |
ES6-Shim // available from https://github.com/es-shims/ | |
Transpiling == Tranforming + compiling; // converts new code into older code equivalents for syntax compatibility. | |
// ES6 | |
function foo(a=2){ // default parameter value == 2 | |
console.log( a ); | |
} |