Tuesday, April 30, 2019

April--->May Post

April--->May

     In the past month, I've been learning about Java and JavaScript language. I've choose to learn this two languages because I have asked my friends about what coding language to learn. They suggested Java and JavaScript, because they are easy to learn,  also the most popular language used in programming and it is easy to read. 

     Java and JavaScript are similar but different. They are similar because there are some similar parts in the lessons that I learn on Codecademy, like the methods, classes and variables. And the different between the two is  that Java creates applications that run in a virtual machine or browser while JavaScript code is run on a browser only. Java code needs to be compiled while JavaScript code are all in text.

     In May, I am planning to finish the JavaScript unit, there is 30% of the unit left and I will also start up another language --- SQL. I chose this new unit because the name sounds interesting to me.

Monday, April 29, 2019

JavaScript(11)---Advanced Objects Introduction

Advanced Objects Introduction

  • The this keyword references the calling object which provides access to the calling object’s properties.
  • the ES6 shorthand is the method showed below at line 5
  • the longhand format is the method showed below at line 4 and 5
One common convention is to place an underscore _ before the name of a property to mean that the property should not be altered. Here’s an example of using _ to prepend a property.
  • Getters are methods that get and return the internal properties of an object. ( if, else etc.)
Notable advantages of using getter methods:
  • Getters can perform an action on the data when getting a property.
  • Getters can return different values using conditionals.
  • In a getter, we can access the properties of the calling object using this.
  • The functionality of our code is easier for other developers to understand.
  • ES6 introduced some new shortcuts for assigning properties to variables known as destructuring.
EX : Use destructured assignment to create a const variable named functionality that extracts the functionality property of robot.





What I learned today? 
I learn a lot of new methods to finish the goal pf the lesson, especially the  ES6 shorthand form.

What I'll be doing tomorrow?

..Introduction to Classes in JavaScript..

Friday, April 26, 2019

JavaScript(10)---Introduction to Objects

Introduction to Objects

A key is like a variable name that points to a location in memory that holds a value. A key’s value can be of any data type in the language including functions or other objects.
We separate each key-value pair in an object literal with a comma (,). Keys are strings, but when we have a key that does not have any special characters in it, JavaScript allows us to omit the quotation marks.
  •  dot notation, .
EX:  1. Create a variable crewCount and assign the spaceship‘s numCrew property to it. 
2. Create a variable planetArray and assign the spaceship‘s flightPath property to it.
  •  using bracket notation, [ ]

NoteWe *must* use bracket notation when accessing keys that have numbers, spaces, or special characters in them. Without bracket notation in these situations, our code would throw an error.

EX:  Using bracket notation and also how to log the variable from the notation above.
  •  the assignment operator, =
You can delete a property from an object with the delete operator.
Notes When the data stored on an object is a function we call that a method.
  • Objects are passed by reference. This means when we pass a variable assigned to an object into a function as an argument, the computer interprets the parameter name as pointing to the space in memory holding that object.

EX: Write a function greenEnergy() that has an object as a parameter and sets that object’s 'Fuel Type' property to 'avocado oil'.
Write a function remotelyDisable() that has an object as a parameter and sets (or reassigns) that object’s disabledproperty to true.

What did I learn? 

What I'm doing tomorrow? 
Moving onto Advanced Objects Introduction

Thursday, April 25, 2019

JavaScript(9)---Iterators

Itnerators

Notice the different methods being called on the arrays:
  • .forEach()will execute the same code for each element of an array but does not change the array and returns undefined.

EX: 

Print:
I want to eat mango
I want to eat papaya
I want to eat pineapple
I want to eat apple
  • .map()takes an argument of a callback function and returns a new array.
EX:

Print:
HelloWorld
[ 1, 2, 3, 4, 5]
  • .filter() returns an array of elements after filtering out certain elements from the original array.
  • .findIndex() on an array will return the index of the first element that evaluates to true in the callback function.  It returns -1 if none of the elements in the array satisfies the condition.
EX: 

  • .reduce()method returns a single value after iterating through the elements of an array, thereby reducing the array. EX: 
Prints: 
  • The some() method tests whether at least one element in the array passes the test implemented by the provided function.
EX: 
Prints: True
  • The filter() method creates a new array with all elements that pass the test implemented by the provided function.
EX: 
  • The every() method tests whether all elements in the array pass the test implemented by the provided function.
EX: 
Prints: True
  • The .reduce( ) take an array that contains multiple values and returns a single value.

What did I learn? 

I learned about a few more methods to test the elements to see if it passes or not. And I also found another website that teaches about coding, the https://developer.mozilla.org/en-US/ it has everything that a developer might need.

What I'll be doing tomorrow? 

OBJECTS in javaScript

JavaScript(8)---HIGHER-ORDER FUNCTIONS intro

HIGHER-ORDER FUNCTIONS
  • Higher-order functions are functions that accept other functions as arguments and/or return functions as output. This enables us to build abstractions on other abstractions, just like “We hosted a birthday party” is an abstraction that may build on the abstraction “We made a cake.”
  • We call the functions that get passed in as parameters and invoked callback functions because they get called during the execution of the higher-order function.
What did I learned?
  1. Abstraction allows us to write complicated code in a way that’s easy to reuse, debug, and understand for human readers
  2. We can work with functions the same way we would any other type of data including reassigning them to new variables
  3. JavaScript functions are first-class objects, so they have properties and methods like any object
  4. Functions can be passed into other functions as parameters
  5. A higher-order function is a function that either accepts functions as parameters, returns a function, or both.
What I'll be doing tomorrow?

Iterators

Wednesday, April 24, 2019

JavaScript(7)---Loops

Loops

  • loop is a programming tool that repeats a set of instructions until a specified condition, called a stopping condition is reached.
  • Instead of writing out the same code over and over, loops allow us to tell computers to repeat a given block of code on its own. 
The typical for loop includes an iterator variable that usually appears in all three expressions.
EX: A for loop contains three expressions separated by ; inside the parentheses:
  1. 1. An initialization starts the loop and can also be used to declare the iterator variable.
2. A stopping condition is the condition that the iterator variable is evaluated against— if the condition evaluates to true the code block will run, and if it evaluates to false the code will stop.
3. An iteration statement is used to update the iterator variable on each loop.
Input:
for (let counter = 0(Indicates that it starts at 0); counter < 4(end with index 4); counter++(Increases by 1 after each loop) { console.log(counter); }
Output:
0
1 2 3

  • To loop through each element in an array, a for loop should use the array’s .length property in its condition.
EX:  Inside the block of the for loop, use console.log() to log each element in the vacationSpots array after the string 'I would love to visit '. For example, the first round of the loop should print 'I would love to visit Bali' to the console.
for (let i = 0; i < vacationSpots.length; i++ ){
  console.log('I would love to visit ' + vacationSpots[i]);
}
Notes:  Remember that arrays are zero-indexed, the index of the last element of an array is equivalent to the length of that array minus 1.
  •  the while loop. 
EX: Create a while loop with a condition that checks if the currentCard does not have that value 'spade'.
while ( currentCard != 'spade')
Math.floor(Math.random() * 4) will give us a random number from 0 to 3
  • do...while statement allows a piece of code to run at least once and then loop based on a specific condition after its initial run.
Unlike the whileloop, do...while will run at least once whether or not the condition evaluates to true.

  • The break keyword allows programs to “break” out of the loop from within the loop’s block.
What did I learn today? 
I learned how to connect codes in the language and know how to do specific jobs or get to specific goals.
What I'm doing tomorrow?
HIGHER-ORDER FUNCTIONS in Javascript