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.


Sunday, 6 November 2016

CSS Selectors

In CSS, apart from just declaring the element selector, you can declare a specific element. For example, if I have many <p> elements and I only want to select a certain <p> element, I can use a specific selector. There is a number of ways of doing this. The first way is to call on the elements id.
I do this by using the hashtag symbol (#), followed by the id name. See the syntax below:


This will also effect every element containing the id "para1" so be careful!

The second way to declare specific element selector is by calling on the class of the element. This is done by placing a .(dot) in front of the class name. This technique is used when you have a group of elements you would like to change. See example below:


Thursday, 3 November 2016

CSS Basic

In this post I will cover the basics of CSS. As I said in my earlier posts, CSS is used to style your webpage. It gives your webpage a 'prettier' and 'nicer' feel.
To begin, you can create a separate style sheet, or you can just place your CSS inside your HTML within <style> tags. I will be using the <style> tags for my example.
Within these <style> tags, you will simply state which elements you would like to style. After this, you will code what style rules you want to change. These style rules will be held within curly brackets {}. Your first declaration, will be to state what you would like to edit (property), followed by the value. See my example below.



In CSS, there is sometimes different ways to declare values, take 'color' for instance. There is three ways to declare a value for color:

            • color: red; - This is declaring it by name
            • color: rgb(255,0,0); - This is declaring it by the formula red, blue and green
            • color: #FF0000 - This is declaring it by Hex. Value
All of the above values will give you the color 'red'.

 It is also possible to obtain double barrel property tags, for example, some of these include:
            • background-image
            • background-repeat
            • background-attachment
            • background-position
            • background-color
            • text-align
            • text-indent
            • text-decoration

Tuesday, 1 November 2016

HTML Lists & Forms

The final part I will cover on HTML is Lists and Forms. As it says on the tin, lists are used to create lists. There are two types of list, un-ordered and ordered. An un-ordered list is used for when it does not matter what order your items are listed in. The ordered list will list your items in ordered numbers.
To create these lists, you will use the <ul> or <ol> tags. Within these tags, you will use the <li> tag to create a List Item. See example below:


Forms are used to give the user a chance to enter some sort of input into your website. This will useful later when we are doing JS as it will enable us to process the users data, but for the meantime we'll just learn how to create forms.
To create a form, you will use the <form> tag. Within these form tags, you will use the <input> tag to create an Input Type. This input type can be anything from a text box to radio buttons. When creating an input, you must state what sort of input it is by using an attribute. e.g. type="text"
See the code and output below for clarification: