This file contains 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 strict"; | |
var Person = { | |
init: function(firstName, lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
return this; | |
}, | |
fullName: function() { | |
return this.firstName + " " + this.lastName; |
This file contains 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
<html> | |
<title>CalculatorJS</title> | |
<style> | |
body { | |
color: #412a0f; | |
} | |
.calculator { | |
width: 20%; | |
margin: 0 auto; |
This file contains 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 createdTime ="Sat Dec 12 2016 18:04:54 GMT+0000"; | |
(function DateTimeDifference( previousTime ) { | |
var today = Date.now(); | |
previousTime = Date.parse(previousTime); | |
var seconds = (today - previousTime) / 1000; | |
var hours = parseInt( seconds / 3600 ); | |
seconds = seconds % 3600; | |
var minutes = parseInt( seconds / 60 ); | |
if(minutes < 60 && hours === 0) { |
This file contains 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 Calculator(num){ | |
return { | |
answer : num ? num : 0, | |
equals : function() { | |
return this.answer | |
}, | |
add : function(num) { | |
this.answer += num ? num : 1 | |
return this | |
}, |
This file contains 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
// 1. Init method | |
var Person = { | |
init: function(firstName, lastName){ | |
this.firstName = firstName; | |
this.lastName = lastName; | |
return this; | |
}, | |
full_name: function(firstName, lastName){ | |
return this.firstName + " " + this.lastName; |
This file contains 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 checkNaN(n){ | |
return (n !== n) ? true : false; | |
} | |
/* | |
If we will use regular "isNaN": | |
isNaN(NaN); // true | |
isNaN(undefined); // true | |
isNaN({}); // true | |
isNaN('123ABC'); // true |
This file contains 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
// Create a function that, given a DOM Element on the page, | |
// will visit the element itself and all of its descendents | |
// (not just its immediate children). For each element visited, | |
// the function should pass that element to a provided callback function. | |
// The arguments to the function should be: | |
// a DOM element | |
// a callback function (that takes a DOM element as its argument) | |
This file contains 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
// Generally speaking: stabilizing the "this" keyword. | |
var person = {hi: "Hello"}; | |
function showFullName(pep) { | |
console.log (this.hi); | |
} | |
showFullName.call(person); | |
// Output: Hello |
This file contains 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
// f(0); // Outputs 0 | |
// f(5); // Outputs 120 | |
function f(n) { | |
// ? stands for if statement - if n = 1 or less will return - n. if n > 1, then n * f(n-1) | |
// f(n); is recursion function | |
return ((n > 1) ? n * f(n-1) : n) | |
} |
This file contains 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
// isInteger(3); // Outputs true | |
// isInteger("5"); // Outputs false | |
// isInteger("car"); // Outputs false | |
function isInteger(x) { | |
// ^ stands for XOR so every integer with (4^0) will give integer itself. Every string will give 0 | |
return (x^0) === x; | |
} | |
// Another solution |
NewerOlder