Ironhack Day 7

JQuery:

1. Preventing default event (in this case the default being the opening of a link when you click it):

$(document).ready(function() {

$(’a’).click(function(event){
event.preventDefault();

alert(”Bye!”);
});

});

2. Selecting DOM elements with JQuery:

$(document).ready(function() {

var container =$(’.container’);
var someId = $(’#someId’)
var menu = $(’.menu’);
console.log(’container ’, container);
console.log(’some Id ’, someId);
console.log(’menu ’, menu);
var menuPlusLi = $(’.menu li’);
console.log(’menuPlusLi’, menuPlusLi);
var menuFirstElement = $(’.menu2 li:first’);
console.log(’menuFirstElement ’, menuFirstElement);

});

3. JQuery cheat sheet: https://oscarotero.com/jquery/

4. Changing the name of a class with JQuery and adding a new class:

console.log(’menu2 class name ’, $(’.menu2’).attr(’class’, ’menu3’));
console.log(’menu2 class name ’, $(’.menu2’).addClass(’newClass’));

Ironhack Day 6

JavaScript

1. Example of using an (anonymous) callback function like setTimeout with an asynchronous method:

function init(){
setTimeout(function(){
console.log(’Hi again!’)
}, 8000)
}

init()
console.log(’Hi!’)

// Hi!
// (after 8 sec) Hi again!

2. Using setInterval with an asynchronous method (it calls a function repeatedly with a fixed delayed time between each call):

var i = 10;
var intervalId = setInterval(function() {
if (i > 0) {
console.log(i);
} else {
console.log(”Pop!”);
clearInterval(intervalId);
}

i–;
}, 1000);

// 10
// 9
// 8 etc.
// Pop!

3. When using prototype it’s the instance of the prototype (here the function Car) that has priority over the prototype itself, that’s why below fiat will be red and not blue:

function Car(){
this.color = ”red”
}

Car.prototype.color = ”blue”

var fiat = new Car()

console.log(fiat.color)

// ’red’

4. To speed up your code it’s better to define properties in the prototype instead of defining them in the constructor (=in the function Car):

function Car(){
//this.color = ”red”

}

Car.prototype.color = ”blue”
Car.prototype.wheelsNum = ”4”

var fiat = new Car()

console.log(fiat.color)

var factory = []

for (var i = 0; i < 100; i++) {
factory.push(new Car(”))
}
console.log(factory)

5. In order to make an object be an instanceof another object you have to use both the .call method and prototype:

function Animal (name, owner, sound) {
this.name = name;
this.owner = owner;
this.sound = sound;
}

function Dog (name, owner){
Animal.call(this, name, owner);
this.sound = ”Guau Guau”;
this.humanRelation = ”love”;
}

Dog.prototype = Object.create(Animal.prototype);

var myAnimal = new Animal(”Arya”, ”Josephine”, ”–”);
var myDog = new Dog(”Max”, ”Owen”);

Bootstrap:
1. Remember to add the jquery cdn at the bottom of your html (see https://code.jquery.com/) before the bootstrap.min.js, like this:

<!– jQuery (necessary for Bootstrap’s JavaScript plugins) –>
    <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js”></script>
    <!– Include all compiled plugins (below), or include individual files as needed –>
    <script src=”js/bootstrap.min.js”></script>
  </body>
</html>

2. Customizing Bootstrap: http://getbootstrap.com/customize/

3. Alternatives to Bootstrap:
http://materializecss.com
http://foundation.zurb.com

4. Free Bootstrap themes: https://bootswatch.com/

Ironhack Day 5

JavaScript:

1. Use ’this’ e.g. when you want to create new objects based on your function (remember to use ’new’ when creating new objects + the convention is to use capital letters for the name of the function in such cases to show they are classes; classes behave like blueprints, prototypes, etc.: they are there in order to enable you with the help of ’new’ to make as many instances of them as you want):

function Car(name){
this.name = name;
this.sayMyName = function() {
console.log(”This car’s name is ” + this.name);
};
}

var kitt = new Car(”Knight Industries Two Thousand”);
var modelS = new Car(”Tesla Model S SuperCar”);

kitt.sayMyName(); // => My name is Knight Industries Two Thousand
modelS.sayMyName(); // => My name is Tesla Model S SuperCar

2. When invoking a method in an object, ’this’ becomes the object itself:

var kitt = {
name: ’Knight Industries Two Thousand’,
sayMyName: function() {
console.log(”My name is ” + this.name);
}
};

var modelS = {
name: ’Tesla Model S SuperCar’,
sayMyName: function() {
console.log(”My name is ” + this.name);
}
};

kitt.sayMyName();
modelS.sayMyName();

3. Simple multiplying function with ’this’:

function Calculator () {
this.total = 0;
this.multiply = function(first, second) {
this.total = first * second;
console.log(this.total);
};
}

var s = new Calculator();
s.multiply(2,3);

4. Calculator with prototype:

function Calculator(){

this.number1 = 0;
this.number2 = 0;
this.result = 0;

Calculator.prototype.askNumber1 = function(){
this.number1 = parseInt(prompt())
}

Calculator.prototype.askNumber2 = function(){
this.number2 = parseInt(prompt())
}

Calculator.prototype.showResult = function(){
console.log(this.result)
}

Calculator.prototype.add = function(){
this.result = this.number1 + this.number2
}

Calculator.prototype.multiply = function(){
this.result = this.number1 * this.number2
}

Calculator.prototype.substract = function(){
this.result = this.number1 – this.number2
}

Calculator.prototype.divide = function(){
this.result = this.number1 / this.number2
}
}
Calculator.prototype.add = function() {
this.result
}
var calc = new Calculator()

calc.askNumber1();
calc.askNumber2();
calc.add();
calc.showResult();

5. Link to DOM (Document Object Model) properties: https://developer.mozilla.org/en-US/docs/Web/API/Document#Properties

6. Link to DOM methods: https://developer.mozilla.org/en-US/docs/Web/API/Document#Methods

Ironhack Day 4

JavaScript:

map is very similar to forEach (both are used to process arrays), except that forEach simply iterates over an array and allow us to do something with each element, while map iterates over an array, BUT returns a new array where each element of the new array is. Examples:

1a. Map:
var array = [1, 2, 3];

var newArray = array.map(function(number){
return number * 2;
})

console.log(newArray);
// [ 2, 4, 6 ]

1b. To achieve the same thing with forEach, you need a longer code:

var array = [1, 2, 3];
var newArray = [];

array.forEach(function(number){
newArray.push(number * 2);
})

console.log(newArray);
// [ 2, 4, 6 ]

2. Another example of using map (turning the first letters of an array’s elements into capital letters):

var cities = [”miami”, ”barcelona”, ”madrid”];

var capsCities = cities.map(function(city){
return city.charAt(0).toUpperCase() + city.slice(1);
})

console.log(capsCities);
// [”Miami”, ”Barcelona”, ”Madrid”]

3a. Using .reduce to get the sum of a number array + print also currentIndex and the array:

var numbers = [2, 4, 6, 8];

var total = numbers.reduce(function(previous, current, currentIndex, originalArray){
console.log(previous, current, currentIndex, originalArray);
return previous + current;
}, 0);

console.log(total);
// 20

3b. Using .reduce to get the sum of a number array:

var numbers = [2, 4, 6, 8];

var total = numbers.reduce(function(previous, current){
/*console.log(previous, current);*/
return previous + current;
}, 0);

console.log(total);
// 20

4a. Calculate the sum of an array’s objects’ properties (like age of persons) using .reduce:

var people = [
{ name: ”Candice”, age: 25 },
{ name: ”Tammy”,   age: 30 },
{ name: ”Allen”,   age: 49 },
{ name: ”Nettie”,  age: 21 },
{ name: ”Stuart”,  age: 17 }
];

var ages = people.reduce(function(sum, person){
return sum + person.age;
}, 0);

console.log(ages);
// 142

4b. Calculate the sum and average of an array’s objects’ properties using .reduce:

var menu = [
{ name: ”Carrots”, calories: 150 },
{ name: ”Steak”, calories: 350 },
{ name: ”Broccoli”, calories: 120 },
{ name: ”Chicken”, calories: 250 },
{ name: ”Pizza”, calories: 520 }
];

var totalCalories = menu.reduce(function(previous, current){
return previous + current.calories;
}, 0);

var averageCalories = totalCalories / menu.length;
console.log(averageCalories);
// 278

5. Using forEach to calculate sum of elements in an array:

var numbers = [1, 2, 3, 4];
var total = 0

numbers.forEach(function(number){
total += number;
})

console.log(total);
// 10

6. Find certain elements in an array with .filter:

var numbers = [1, 2, 3, 4, 5, 6];

var evens = numbers.filter(function(number){
return number % 2 === 0;
});

console.log(evens);
// [ 2, 4, 6 ]

7a. Sorting an array’s elements in numerical order from lowest to highest:

var numbers = [22, 23, 99, 68, 1, 0, 9];

console.log(numbers.sort());
// [ 99, 68, 23, 22, 9, 1, 0 ]

7b. Sorting an array’s elements in numerical order from highest to lowest:

var numbers = [22, 23, 99, 68, 1, 0, 9];

numbers.sort(function(a, b){
// switch the order of the comparison
return b – a;
});

console.log(numbers);
// [ 99, 68, 23, 22, 9, 1, 0 ]

8. The thisIsMyCB function below is called a callback or higher order function, i.e. you pass a function as an argument and use it inside the other function (more about callback functions: http://callbackhell.com):

function main(thisIsMyCB){
var something = ”bla”;
thisIsMyCB(something);
}

main(function(something){ /*FUNCTION HERE REFERS TO thisIsMyCB*/
console.log(”I’m anonymous ” + something)
})

9. Sort string array alphabetically:

var words = [”Hello”, ”Goodbye”, ”First”, ”A”, ”a”, ”Second”, ”Third”];

words.sort()

console.log(words);

10. Sort string array in descending alphabetical order:

var words = [”Hello”, ”Goodbye”, ”First”, ”A”, ”a”, ”Second”, ”Third”];
words.sort(function(a, b){
if (a > b){ return -1; }
if (a < b){ return 1; } return 0; }); console.log(words); 11. Sort string array by length: var words = [”Hello”, ”Goodbye”, ”First”, ”A”, ”a”, ”Second”, ”Third”]; words.sort(function(a, b){ if (a.length > b.length){ return -1; }
if (a.length < b.length){ return 1; }
return 0; });
console.log(words);
//[ ’Goodbye’, ’Second’, ’Hello’, ’First’, ’Third’, ’A’, ’a’ ]

12. Lodash JS library: https://lodash.com/docs/

Ironhack Day 3

Thought of the day: huge amount of new things to process, not much time to digest them.

My notes from the class:

JavaScript:

1. In order to assign the property of an object to a variable you have to use bracket notation, e.g.:

var columns = {
left: true,
center : false,
right : false
}
var side = columns[’left’];
console.log(side);

2. Accessing properties of an object example 1:

var user = {
name: ”snoopy”,
age: 25,
size: ”small”,
toys: [”bone”, ”ball”],
address: {
street: ”bla”,
number: 23
}
}

console.log(user.toys[1]);
console.log(user.address)
console.log(user.address.street)

Accessing properties of an object example 2:

var book1 = { title: ”The Catcher in the Rye”, author: ”J.D Salinger”, isbn: ”0316769487”, category: ”Classic Literature” };
var book2 = { title: ”To Kill a Mockingbird”, author: ”Harper Lee”, isbn: ”0446310786”, category: ”Classic Literature” };

var library =[book1, book2]
console.log(library[1].title)

3. Accessing properties of an object containing an array:

var library= [
{ title: ”The Catcher in the Rye”, author: ”J.D Salinger”, isbn: ”0316769487”, category: ”Classic Literature” },
{ title: ”To Kill a Mockingbird”, author: ”Harper Lee”, isbn: ”0446310786”, category: ”Classic Literature” }
]

console.log(library[0].title)

4. If you use an array inside an object instead of an object inside an object it will be easier to access the respective properties. Example:

var classRoom = {
teacher: { firstName: ’Marcelino’, lastName: ’Padberg’, age: 25 },
students: [
{ firstName: ’Aliyah’, lastName: ’Schulist’, age: 18 },
{ firstName: ’Cleveland’, lastName: ’Towne’, age: 28 },
{ firstName: ’Jan’, lastName: ’Quitzon’, age: 18 },
{ firstName: ’Alaina’, lastName: ’Runolfsdottir’, age: 18 },
{ firstName: ’Gerhard’, lastName: ’Bergstrom’, age: 23 }
]
};

console.log(classRoom.students[2].firstName);
// ’Jan’

console.log(classRoom.teacher.age);
// 25

CSS:

1. Something I didn’t know about advanced selectors:

advanced selectors in css

2. Useful site if planning to use transitions: http://cubic-bezier.com/

3. If planning to do css animations, you might find this site useful: https://daneden.github.io/animate.css/

4. For inspiration on how to use keyframes for css animations check e.g. https://codepen.io/tag/keyframes/

Ironhack Day 2

There are two kinds of students here: those who have spent years programming and/or have a science degree and the rest. I belong to the latter category. For the former group this bootcamp is a stroll in the park, for the latter it’s overwhelming. That’s just how it is, trying to face the music and hope I’ll come out of this experience with a bit more solid knowledge of web dev than what I’ve had before.

That being said here are my notes from day 2:

CSS:

Learned that the absolutely positioned div is relative to its parent if the latter is positioned relatively. If there’s no such parent, then it will be positioned relatively to the body.

JavaScript:

Learned i.a. about anonymous functions, recursion, high-order functions and forEach method, see details below.

1. Anonymous function:

var anon = function(){
console.log(”An0nym0us Funct10n”);
}

anon();

When calling this function the function itself will be printed, i.e. ”Function: anon”, instead of ”An0nym0us Funct10n”.

2. Recursion (function definitions that are implemented in a way they use their own definitions. It’s like function inception. Btw factorial of a non-negative integer n is the product of all positive integers less than or equal to n, e.g. 5 ! = 5 × 4 × 3 × 2 × 1 = 120):

function factorial(number) {
if (number === 0) { return 1; }
return number * factorial(number – 1);
}

3. High-Order Functions: functions can return functions or receive other functions as parameter.

var add = function (a) {
return function (b) {
return a + b;
};
};

var add2 = add(2);
add2(3);
// => 5

add(4)(5);
// => 9

4. forEach:
Example nr 1:
var raceResults = [’Hellen’, ’John’, ’Peter’, ’Mery’];
raceResults.forEach(function(elem, index){
console.log(elem + ’ finished the race in ’ + (index+1) + ’ position!’);
});

Example nr 2:
function averageWordLength(words) {
var sum = 0;
words.forEach(function(word){
sum = sum + word.length;
})
var average = sum/words.length;
return average;
}

var words = [
”seat”,
”correspond”,
”linen”,
”motif”,
”hole”,
”smell”,
”smart”,
”chaos”,
”fuel”,
”palace”
];
var averageLength = averageWordLength(words);
console.log(averageLength);

Syntax:
arr.forEach(function callback(currentValue, index, array) {
//your iterator
}[, thisArg]);

Ironhack Day 1

On the first day of my Ironhack Web Dev Bootcamp our teacher, Thor (great name, btw!) made a super-quick summary of Git, Github, HTML, CSS and JavaScript (mainly things we’ve had to read for the pre work exercises of the bootcamp). Below are the things that grabbed my attention:

Git & Github:

  • touch index.txt (create file)
  • nano index.txt (open the files, used for making small changes)
  • cat index.txt (check what the file contains)
  • going back to previous versions with the help of git log, was introduced to the concept of HEAD

 

JavaScript:
The following notes are related to the pair work we did after the actual teaching. Even though my head was spinning after that, given the fast pace at which my team mate, who’s been working with JS for 6 years, was coming up with different possible solutions to the exercises, it’s been incredibly useful for me. Besides the things listed below my main take-away was seeing in action how one translates to JS’ logic (functions, loops, if statements & all that jazz) the instructions given in more or less plain English.

  • use of functions: noticed there are two cases where we were supposed to print words backwards
  • use of .indexOf for ”translating” characters from a string into numbers (=their position in the string) in order to check which of the strings comes first in an alphabetical order
  • use of .replace in order to be able to ignore spaces between words when checking whether the string entered by the user is a palindrome or not
  • counting number of words in a text by checking how many blank spaces the text contains
  • counting how many times a word has been used in a text by checking: 1. if the first characters of the text match with the word we’re looking for; 2. if there are in the text cases when a blank space is followed by these characters, which are in turn followed by another blank space.

Got My Mind Set on You Part 2

Remember me saying last November that my long term goal is to get filthy rich, get a 13 weeks unpaid vacation and take a job guaranteed web dev bootcamp course? Well, I haven’t gotten rich (au contraire), but I did get a 3 months unpaid vacation and took an on-site web dev bootcamp that kind of guarantees a web developer job. The ”kind of means” here that the school (Ironhack) is pretty sure I could get a job after the course in the city where they hold these courses, the city being Barcelona. So, here I am in Barcelona, full of hopes and anxieties and freaked out and thrilled by the prospect of studying web dev about 11 hours a day (most of this time spent on pair work and individual work) for a while. I’ll try to post from now on at least once a week about my progress, just to keep track of what I’ve learned & make sure these things won’t be completely wiped out of my memory once I’ve finished the course.

Little big victory

The portfolio page and the slider on the homepage didn’t render correctly for a couple of days due to plugins related problems. It took me some time to figure out what the issue was, but now everything looks just as good as on Thursday 10 Nov (thanks God I’ve had my site backed up)!

Relieved face emoji

P.S. Big thanks to my testing team temporarily located in Montevideo, Uruguay ; – ) Ay carramba!

 

Got My Mind Set on You

In my Fixin’ Frenzy post I was saying that by the end of October I’ll be much wiser, so I it’s about time for me to mention something about my web dev studies, what I’ve learned and what I’ll do next. And perhaps something about how wise I really am right now, as well…

What I can say for certain is that thanks to the Skillcrush courses I’m more confident in my HTML and CSS skills, plus I’ve finally managed to make my own Git repo at https://bitbucket.org/imbjim. That makes me a bit web dev wiser, I guess.

So, what’s next? I have two relatively short term goals (no deadline for them, though):

– Get better at JavaScript.

– Experiment a bit more with turning static websites into WordPress sites.

As far as goal number one is concerned, I’ve already started a JavaScript course that so far has been amazing (I’m halfway thru the course): https://watchandcode.com by Gordon Zhu. For reaching goal number two I still have to do some thinking and sniffing around the internet. Anyway, I’m working on it. Kind of.

P.S. I also have a long term goal: get filthy rich, get a 13 weeks unpaid vacation and take a job guaranteed web dev bootcamp course.

P.P.S. The ”You” in ”Got my Mind Set on You” stands for my older goal of turning from a newbie web developer into a rookie web developer and then into the master of the universe.