Thursday, 17 November 2016

Video: Website - HTML, CSS & JS

For my final post, I created a screen-cast below. This video will show you a website which I created using all the tools we have seen in this blog..


Tuesday, 15 November 2016

JavaScript While Loop & If Statement

In this lesson we will look at loops and if statements. Loops can execute a block of code as long as a specified condition is true. A while loop will loop through the block of code as long as the condition is true. The below is the syntax of a while loop:

while (condition) {
    code block to be executed
}

To stop your loop from running infinitely, you must update the condition after every execution of the code. An example of this would be to use a counter. See my example below.

As you can see the loop will run until the condition is no longer through. This is done by using a counter (i++).

The if statement is used to check if a condition is true and you want to run a block of code that might be related to that condition. Use the if statement to specify a block of JavaScript code to be executed if a condition is true. Use the else statement to specify a block of code to be executed if the condition is false. Syntax is below:

if (condition) {
    block of code to be executed if the condition is true} else { 
    block of code to be executed if the condition is false}

See the screenshots below for an example of this code being used.




Notice how when I change the value for 'hour', it runs a different block of code which places a different value into 'greeting' each time.

Sunday, 13 November 2016

JavaScript Variables & Arithmetic

In JavaScript you can create variables which create a container for storing values. To create a variable, you must declare it by writing 'var', followed by the name of the variable, then the assignment operator, and then the value.
For example: var example = 1;
This would create a variable called 'example' with the value '1'. When deciding the name, you must remember that you are not able to start the name with a number.
Variables can hold different types of values, such as integers, doubles, characters or strings. An integer would be a single number (e.g. 5, 32, -642). A double is a number with a decimal point (e.g. 2.1, 54.66, -0.1). A character is a single character (e.g. d, T, ^) and a string is a list of characters (e.g Hello, WoRlD, hgfds). See below for examples:

The most important rule when working with variables is to never mix the type of variables together. This will make sense when we get in to the arithmetic.

It is possible to do arithmetic with variables such as add (+), subtract (-), divide (/) and multiply (*). When adding variables together, it is best to place the new value into a separate variable.
See an example of these below.




Friday, 11 November 2016

JavaScript Style Properties & Box Model

In this tutorial, we will be learning how to use a number of common style properties, along with learning about the CSS box model. The style properties we will be going through are 'border', 'margin', 'margin-style' and 'background-color'.
We will start with border. A border is useful when you would like to place a border around a certain element. When using a border, you must select the type of the border you want, you will give the value of thickness, type and color.
The next style property is the margin property. When using this, you must declare the size of the margin you want.
When selecting a border, it is possible to give it a certain style by using the border-style property.
The background-color property is used when you would like to add a background color on the element.
See below for examples of all these properties being used:



The CSS Box Model
All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout. The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content. See image below on how to use.
  • Content - The content of the box, where text and images appear
  • Padding - Clears an area around the content. The padding is transparent
  • Border - A border that goes around the padding and content
  • Margin - Clears an area outside the border. The margin is transparent


Thursday, 10 November 2016

JavaScript Functions

The final language I will post about is JavaScript. If you have programmed in Java before you will find that JavaScript is pretty similar. JavaScript is used to make your website more interactive for the user.
To begin using JavaScript, you must write learn how to write a function. A function is a method that allows you to alter the webpage. This is done by placing an 'onclick' attribute inside of your HTML element. There is many different types of functions you can write, from very basic to complex functions. Like CSS, your functions can be declared within your HTML page or on an external JavaScript sheet. I have created a very simple function, see below:





In the first image you can see the code and the webpage when it initially loads. The second image shows you what happens when the button is clicked. When the button is clicked, it runs the function 'displayDateTime'. Within this function I have a statement which looks for the id 'demo'. Once this is found, it places the date and time in the element which has that id. The date and time is found using a pre-defined class called date(). This is a pre-written so you don't have to write it.


Wednesday, 9 November 2016

Video: Website - HTML & CSS

For your viewing, I created a screen-cast below. This video will show you a basic website which I created using all the tools we have seen already.