Skip to content

Instantly share code, notes, and snippets.

@KimSarabia
KimSarabia / loopingatriangle.js
Last active October 17, 2015 22:20
Eloquent Javascript Ch1:Q1
var hashtag = "#";
while (hashtag.length <= 7) {
console.log(hashtag);
hashtag += "#";
}
@KimSarabia
KimSarabia / FizzBuzzPt1.js
Last active October 17, 2015 22:19
Eloquent Javascript Ch. 2 Q2
for (var i = 1; i <= 100; i++)
if(i % 3 == 0)
console.log("Fizz");
else
console.log(i);
<!-- //// Result 1
2
Fizz
4
@KimSarabia
KimSarabia / FizzBuzz_Pt2.js
Last active October 17, 2015 22:18
Eloquent Javascript Ch. 2 Q2
for (var i = 1; i <= 100; i++)
if(i % 3 == 0)
console.log("Fizz");
else if(i % 5 == 0)
console.log("Buzz");
else
console.log(i);
<!-- 1
2
@KimSarabia
KimSarabia / FizzBuzz_Pt3.js
Last active October 17, 2015 22:19
Eloquent Javascript Ch. 2 Q2
for (var i = 1; i <= 100; i++)
if ((i % 3 == 0) && (i % 5 == 0))
console.log("FizzBuzz");
else if (i % 3 == 0)
console.log("Fizz");
else if (i % 5 == 0)
console.log("Buzz");
else
console.log(i);
@KimSarabia
KimSarabia / chessboard_1st_attempt.js
Last active October 17, 2015 22:17
Eloquent Javascript Ch. 2 Q3
for (var i = 0; i < 4; i++) {
console.log(" "+"#"+" "+"#"+" "+"#"+" "+"#"+"\n");
for (var j = 0; j < 1; j++) {
console.log("#"+" "+"#"+" "+"#"+" "+"#"+" "+"\n");
}
}
// Answer:
// # # # #
// # # # #
// # # # #
@KimSarabia
KimSarabia / closure.js
Last active November 5, 2015 01:55
Eloquent Javascript Ch. 2 Functions Exercises
//Don't understand functions very well. Decided to write
//it in a way that I would understand as a former finance associate.
function insurancecost(fee) {
return function(staffsize) {
return staffsize * fee;
};
}
var portlandoffice = insurancecost(30000);
console.log(portlandoffice(97))
@KimSarabia
KimSarabia / min.js
Created November 5, 2015 20:17
Eloquent JavaScript Chapter 3 Q.1
function min(x,y) {
if (x > y)
return y;
else (x < y)
return x;
};
console.log(min(0, 10));
// → 0
console.log(min(0, -10));
// → -10
@KimSarabia
KimSarabia / myCat.js
Created November 8, 2015 16:39
Learning Objects W3 Schools
<!DOCTYPE html>
<html>
<body>
<p>My Cat is...</p>
<p id="demo"></p>
<script>
var myCat = {texture:"fluffy", breed:"Calico", color:"white", age: 4};
@KimSarabia
KimSarabia / reverse.js
Created November 11, 2015 23:59
CH Challenge #10
function reverse(string) {
for (var i = string.length - 1, o = ''; i >= 0; o += string[i--]) { }
return o;
}
console.log(reverse("I love Coding House!"));
@KimSarabia
KimSarabia / counterfunction.js
Last active November 30, 2015 23:19
CH Challenge #4
/* Write a javascript counter function that takes a text argument and count the following:
Number of words in the text
Number of characters in the text
Number of spaces in the text
Average word length
Test case