Tuesday, November 30, 2021
<script> functionCount.counter = 0; function functionCount() { return functionCount.counter++; } for (var i = 0; i < 10; i++) functionCount(); console.log(functionCount.counter); </script>
Monday, November 29, 2021
Let say you have an the following array:
var numbers = [3,4];
If you output the array in the browser console you will see that the array has two elements with the number 3 occupying index 0 and the number 4 occupying index 1.
Friday, November 26, 2021
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");
}
Thursday, November 25, 2021
Let's say you have an array with the following:
var numbers = ["one","two","three","four","five"];
The numbers array above contains five string elements, which also has a indexes associated with the it. There's also a length that is defined with each array that we will use for the for loop we are about to write. So what do the you length of the numbers array will be?
If we output the array to the browser with the statement console.log(numbers.length) do you think we will get the length to be 5 or 4?
If you guess 5 you are correct because there are five elements in the array. However, the arrays have zero based indexes therefore the index is always length -1
for(var i = 0; i < numbers.length; i++)
{
console.log(numbers[i]);
}
Wednesday, November 24, 2021
Let's say you have the following database Products table
Tuesday, November 23, 2021
Here are the steps:
1. Go to https://www.mongodb.com/download-center/community, then click on the "Download" button
Monday, November 22, 2021
So let's declare our array from 1 to 5
<script> var numbers = [1, 2, 3, 4, 5]; </script>
So if we call the numbers.reverse() method we should get an array of 5 to one in the reverse order
Friday, November 19, 2021
- 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
Thursday, November 18, 2021
<script> var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99]; var total = 0; oilPrices.forEach(function (value) { total += value }); console.log(total); </script>
Wednesday, November 17, 2021
In the previous post we created a load balancers with the target groups, rules, and instances to handle HTTPS traffic. In this post we are going to set up our DNS records in Route 53. So go to the Route 53 dashboard, click on your domain
1. Click on "Create record"
Tuesday, November 16, 2021
One of the first thing you want to do is to connect to MongoDB so that you can run more commands.
Here is the command to connect to MongoDB
mongo --host=localhost --port=27017
All you need is the name of the host and port number, 27017 is the default port number and since we running the command on the MongoDB host, the host is localhost
Monday, November 15, 2021
<script> var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99]; var discounted = oilPrices.map(function (value) { return value -1; }); console.log(discounted); </script>
Friday, November 12, 2021
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
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:
Wednesday, November 10, 2021
In the previous post we created four instances with a Launch Template. In this post we are going to add DNS records in Route 53 and configure our Application Load Balancer with our certificates.
Before we start creating stuff let's take a step back and look at how we want to configure the website. Let's say a bank wants to branch out into investing, so it wants to dedicate to instances to it's investing arm. In our architecture we would have two target groups, one target group handling traffic for https://acmebanking.com and the other target group handling traffic for https://investing.acmebanking.com
We are going to register all four instances on the load balancer.
1. So now we ready to create an Application Load Balancer, give it a name and for the listener add an HTTPS listener to the existing one
Monday, November 8, 2021
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
eval("4+5") the result will be 9 even though it's a string
Thursday, November 4, 2021
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);
};
Wednesday, November 3, 2021
In the previous post we created our certificates in the Certificate Manager, in this post we are going to create four instances using a Launch Template so that we could use it in our load balancer.
1. We are actually going to use "Launch Template" to create our instances, so click on "Launch Templates" under "Instances" in the EC2 Dashboard
Tuesday, November 2, 2021
Here are the steps:
1. Download the community edition of MongoDB from the page https://www.mongodb.com/download-center?jmp=nav#community click on the "Linux" tab is selected and select the Linux version that you want
Monday, November 1, 2021
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);