Skip to content

Instantly share code, notes, and snippets.

@jgresalfi
jgresalfi / hs-boilerplate.css
Created May 3, 2016 14:34
Hubspot Boilerplate CSS
/* @import url('http://example.com/example_style.css'); */
/**
* CSS @imports must be at the top of the file.
* Add them above this section.
*/
/* ==========================================================================
/* If you have a sticky bar at the top of a webpage that's the same color as the page background, this will fade in a drop shadow below the bar to create a boundary on scroll */
// jQuery
$(document).ready(function(){
var a=$(".sticky-top-bar");
$(window).scroll(function(){
if($(document).scrollTop()>50){a.addClass("top-bar-shadow")
}else{a.removeClass("top-bar-shadow")}})});
@jgresalfi
jgresalfi / randNum.js
Last active September 4, 2016 20:16
Random number guessing game.
"use strict";
var upper = 10000,
numToGuess = getRandomNumber(upper),
compGuess = getRandomNumber(upper),
numOfGuesses = 0,
correctGuess = false;
function getRandomNumber(upper) {
return Math.floor( Math.random() * upper ) + 1;
@jgresalfi
jgresalfi / randNum_v2.js
Created September 4, 2016 20:17
Random number guessing game - refactor
"use strict";
var upper = 10000,
numToGuess = getRandomNumber(upper),
compGuess,
numOfGuesses = 0;
function getRandomNumber(upper) {
return Math.floor( Math.random() * upper ) + 1;
}
@jgresalfi
jgresalfi / eyePalindrome.js
Created September 4, 2016 20:18
Palindromes and regexp...hooray!
function palindrome(str) {
// Good luck!
var re = /[\s\!\@\#\$\%\^\&\*\(\)\+\=\-/\\\\:\_]/g,
cleanStr,
revStr;
cleanStr = str.toLowerCase().replace(re, "");
revStr = cleanStr.split("").reverse().join("");
if (cleanStr === revStr) {
return true;
} else { console.log(cleanStr); }
@jgresalfi
jgresalfi / factorializer.js
Created September 4, 2016 20:20
Factorial! factory.
function factorialize(num) {
var facArray = [];
if (num === 0) {
return 1;
} else {
for (var i = 1; i <= num; i++) {
facArray.push(i);
@jgresalfi
jgresalfi / recordCol.js
Created September 4, 2016 20:22
Modifying objects/checking properties - record collection example
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
@jgresalfi
jgresalfi / reverseStr.js
Created September 4, 2016 20:22
Reversing strings
function reverseString(str) {
var strArray = str.split("");
strArray.reverse("");
return strArray.join("");
}
reverseString("hello");
@jgresalfi
jgresalfi / phoneBuyerz.js
Created September 4, 2016 20:23
Silly phone buying app...
"use strict";
const SALESTAX = .0975,
PHONE_PRICE = 200.00,
ACCESS_PRICE = 40.00;
var ba = prompt("How much money you got?"),
ac = prompt("When to stop buying accessories?"),
bankAccount = parseInt(ba),
accessoryLimit = parseInt(ac),
@jgresalfi
jgresalfi / longWord.js
Last active September 5, 2016 02:45
Find longest word in a string.
function findLongestWord(str) {
var strArray = str.split(" "),
arrCount = [];
for (var i = 0; i < strArray.length; i++) {
arrCount.push(strArray[i].length);
}
return Math.max(...arrCount);
}
findLongestWord("The quick brown fox jumped over the lazy dog");