Latest Posts
Showing posts with label Computer Programming. Show all posts
Showing posts with label Computer Programming. Show all posts
Friday, December 3, 2021
In JavaScript the DOM is an acronym for "Document Object Model" that's quite a mouthful. Most people just refer to it as the DOM. The DOM is basically a collection of objects/elements organized in the tree structure. To perform any functions in JavaScript you first have to find a reference to the object or element you are working with. Luckily, there are a few handy JavaScript methods that can help you find the elements in the DOM that you want.
Let's take a look at the methods:
Let's take a look at the methods:
- getElementById - this method gets the element based on the unique id that is assigned to the element
- getElementByClassName - this method gets the elements that has the class name that is passed into the method
- getElementByTagName - this method gets the elements that matches the tag name
- querySelector - this method gets the first child element that matches the CSS selector being passed in
- querySelectorAll - this method gets all the child elements that match the CSS selector
Friday, November 26, 2021
The switch statement is there to make the code more readable if the if statements contains too many branches and becomes too hard to read.
Consider the code below
var x = 6;
if (x === 1)
{
console.log("one");
}
else if (x === 2)
{
console.log("two");
}
else if (x === 3)
{
console.log("three");
}
else if (x === 4)
{
console.log("four");
}
else if (x === 5)
{
console.log("five");
}
else
{
console.log("x is not 1-5");
}
Consider the code below
var x = 6;
if (x === 1)
{
console.log("one");
}
else if (x === 2)
{
console.log("two");
}
else if (x === 3)
{
console.log("three");
}
else if (x === 4)
{
console.log("four");
}
else if (x === 5)
{
console.log("five");
}
else
{
console.log("x is not 1-5");
}
Friday, November 19, 2021
The for loop is a looping construct in JavaScript that are more simplistic than the while loop. When writing the for loop there are three three parts they are
- Initialize - a count variable is initialize, it's usually zero but it doesn't have to be
- Test - A test to see if the loop should continue
- Increment - finally the count is incremented, it doesn't have to be an increment it could be decrements as well
Let's use the JavaScript code to demonstrate:
If you execute the loop below you will bet a for loop that executes when i is less than 10
for (var i = 0; i < 10; i++)
{
console.log("i is " + i);
}
console.log("i outside of for look is " + i);
Friday, November 12, 2021
The conditional ?: operator in JavaScript has three operands the first part goes before ? the second goes between the ? and the : symbol and the third operand goes after the : symbol. You can think of this operator as shorthand way of writing a an if statement. The first operand evaluates to a boolean, if the first operand is true then evaluate the second operand else evaluate the third operand.
Let's say we want to want to see what the gender of the baby is and assign it a name, let's demonstrate it with code.
var gender = "girl";
var name = gender === "boy" ? "Julian" : "Julie";
console.log(name);
The code above assigns the variable gender to "girl" then it uses the conditional ?: to assign a value to the variable name if the gender is "boy" then assign the name "Julian" to name, else assign the name "Julie"
Let's say we want to want to see what the gender of the baby is and assign it a name, let's demonstrate it with code.
var gender = "girl";
var name = gender === "boy" ? "Julian" : "Julie";
console.log(name);
The code above assigns the variable gender to "girl" then it uses the conditional ?: to assign a value to the variable name if the gender is "boy" then assign the name "Julian" to name, else assign the name "Julie"
Thursday, November 11, 2021
JavaScript error handling is a lot like other languages where you have the try/catch/finally statement that you can used. The basic premise is
try
{
// try some codes here fingers crossed that nothing bad happens
}
catch(ex)
{
// oops something bad happened, this is where it gets handled or I tell the user
}
finally
{
// I don't care what happens I am going to execute and get paid
}
Here is the error handling in action:
try
{
// try some codes here fingers crossed that nothing bad happens
}
catch(ex)
{
// oops something bad happened, this is where it gets handled or I tell the user
}
finally
{
// I don't care what happens I am going to execute and get paid
}
Here is the error handling in action:
Monday, November 8, 2021
The most common ways you see how objects are created in JavaScript is the object literal syntax. The object literal syntax is the open { } with comma separated name: pair value lists. The name: part is the name of the property. The part after : is the property value which can hold a primitive value or another object. It could even be a function.
Here is an example of an object literal:
var product = {
name: "Chai",
Category: "Tea",
Country: "India",
supplier: {
name: "ACME Tea Of India",
location : "New Delhi"
},
related: ["Earl Grey", "Green Tea", "Dark Tea", "White Tea"],
display: function () {
console.log(this);
}
};
Here is an example of an object literal:
var product = {
name: "Chai",
Category: "Tea",
Country: "India",
supplier: {
name: "ACME Tea Of India",
location : "New Delhi"
},
related: ["Earl Grey", "Green Tea", "Dark Tea", "White Tea"],
display: function () {
console.log(this);
}
};
Friday, November 5, 2021
The eval() function in JavaScript provides the power of dynamic evaluation, it evaluates a strings of JavaScript codes and returns a value. If you use the eval on pair of string numbers it will be forgiving and give you the number if it can. For example if you type int
eval("4+5") the result will be 9 even though it's a string
eval("4+5") the result will be 9 even though it's a string
Thursday, November 4, 2021
In the previous post we visited how to create an object with an object literal. In this post we are going to create the same object using the new keyword. When creating objects using the new keyword it is required that the it is followed by a function call. The purpose of this function call is the needs a way to call to the constructor of the new object. A constructor is used to create or initialize the created object.
Here is the code to rewrite our literal object using the new keyword:
var product = new Object();
product.name = "Chai";
product.category= "Tea";
product.country= "India";
product.supplier= {
name: "ACME Tea Of India",
location: "New Delhi"
};
product.related = new Array("Earl Grey", "Green Tea", "Dark Tea", "White Tea");
product.display = function () {
console.log(this);
};
Here is the code to rewrite our literal object using the new keyword:
var product = new Object();
product.name = "Chai";
product.category= "Tea";
product.country= "India";
product.supplier= {
name: "ACME Tea Of India",
location: "New Delhi"
};
product.related = new Array("Earl Grey", "Green Tea", "Dark Tea", "White Tea");
product.display = function () {
console.log(this);
};
Monday, November 1, 2021
Object.Create( ) is a static function which can take two arguments. The first argument is the prototype of the object, while the second argument is the properties of the argument. A prototype is a second object that is created with every JavaScript object. It is like a blueprint, or the model that the object is built on. Think of it as a car prototype.
So let's create an object with Object.Create( ) function:
var person = Object.create({
name: "Tech Junkie",
location: "Mars",
hobbie: "Video Games"
});
console.log(person);
So let's create an object with Object.Create( ) function:
var person = Object.create({
name: "Tech Junkie",
location: "Mars",
hobbie: "Video Games"
});
console.log(person);
Thursday, October 28, 2021
In JavaScript there are two ways to access an object, first by dot notation like this
product.name
or with array notation
product["name"]
They both get the job done. However with the array syntax [""] you access the object as if it's an array but instead of accessing it by numbers or index you access it by the property names. That's because JavaScript objects are associative arrays. They look like other objects in other languages such as C, C++, and Java. However they behave very differently.
In other languages objects are defined in advance, their properties are methods are fixed. To add a property or method to the object you have to change the class the object instance is created from.
product.name
or with array notation
product["name"]
They both get the job done. However with the array syntax [""] you access the object as if it's an array but instead of accessing it by numbers or index you access it by the property names. That's because JavaScript objects are associative arrays. They look like other objects in other languages such as C, C++, and Java. However they behave very differently.
In other languages objects are defined in advance, their properties are methods are fixed. To add a property or method to the object you have to change the class the object instance is created from.
Thursday, October 7, 2021
The while loop statement in JavaScript simply executes a statement block until a condition is not true anymore the syntax for the while loop is as follow
while (expression is true)
{
execute these statements
}
The while loop is an iterative loop if the condition is true and the statements are executed, it starts at the top of the loop again and executes until the expression is false. Therefore, there's a potential for an infinite loop.
while (expression is true)
{
execute these statements
}
The while loop is an iterative loop if the condition is true and the statements are executed, it starts at the top of the loop again and executes until the expression is false. Therefore, there's a potential for an infinite loop.
Monday, October 4, 2021
The do/while loop is similar to the while loop. The difference is that the first the loop expression is tested after the do statement block is executed at least once. For example let's use our countdown example again.
If we have the code below the countdown displays the same results as the output. However, the first iteration is performed without a evaluation of the expression. It's not until the countdown is 9 that the while part of the loop kicks in.
If we have the code below the countdown displays the same results as the output. However, the first iteration is performed without a evaluation of the expression. It's not until the countdown is 9 that the while part of the loop kicks in.
Thursday, September 30, 2021
The for/in loop is a for loop that is used to iterate through the variables in an object. It can iterate to through that anything that can evaluated on the left side of the assignment expression call the LValues. Let's use the for/in loop to iterate through an object "person".
Here we created an object called "person" with three properties we are going to use the for/in loop to display the property names as well as the values of those properties
var person = new Object();
person.name = "Tech Junkie";
person.occupation = "Blogger";
person.location = "Mars";
for(var p in person)
console.log(p + ": " + person[p]);
Here we created an object called "person" with three properties we are going to use the for/in loop to display the property names as well as the values of those properties
var person = new Object();
person.name = "Tech Junkie";
person.occupation = "Blogger";
person.location = "Mars";
for(var p in person)
console.log(p + ": " + person[p]);
Tuesday, August 17, 2021
The first thing you want to do in Python is to install the latest version of Python. Even though most Linux and MAC distribution has Python installed by default, you still want to install the latest version of Python. The latest stable version of Python at the time of this writing is version 3.8.5 in this post we are going to install version 3.6.5 on our Linux instance.
1. Open up the terminal and type the following commands
sudo su
mkdir /opt/python
cd /opt/python/
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz
tar xzf Python-3.8.5.tgz
What we did was basically was create a new folder called python to hold our files and then download the python version 3.8.5 and then unpack the file with the tar xzf command
Thursday, April 5, 2018
In this post I am going to go over how to install Python on a Windows machine
Here are the steps to install Python
1. Type in the URL https://www.python.org/downloads/
2. Click Download Pythong 3.6.5, save it to a location that you will remember
Here are the steps to install Python
1. Type in the URL https://www.python.org/downloads/
2. Click Download Pythong 3.6.5, save it to a location that you will remember
Sunday, June 19, 2016
Namespace:
System.Collections.Generic
Declaration:
Adding Items:
Use in ArrayList: Namespace:
System.Collections.Generic
Declaration:
Dictionary<string, string> account = new Dictionary<string, string>();
Adding Items:
account.Add("id","1"); account.Add("username", "jackd");
Use in ArrayList: Namespace:
Thursday, March 26, 2015
There are times when you see a class property without it's private member counterpart and all you see is the {set; get;} accessors. What you are looking at are auto properties that you can create in C#, the only requirements is that the set; and get; accessors contains no logic. Usually there are private members that the properties expose to other classes using the get/set accessors, like the code below:
public class Product { private int productId; private string name; private string description; private decimal price; public int ProductId { get { return productId; } set { productId = value; } } public string Name { get { return name; } set { name = value; } } public string Description { get { return description; } set { description = value; } } public decimal Price { get { return price; } set { price = value; } } }
Thursday, February 19, 2015
Arrays are fixed size elements of a type, arrays are stored next to each other in the memory. Making them very fast and efficient. However you must know the exact size of an array when you declare an array.
Declaring an array:
Declaring an array:
string[] names = new string[5];There are two ways you can assign values to an array. The first is to assign the values individually by specify the index of the array inside a square bracket. The index is the position of element in the array. Index starts with 0.
names[0] = "George"; names[1] = "James"; names[2] = "Arthur"; names[3] = "Eric"; names[4] = "Jennifer";
Subscribe to:
Posts (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu