LaurenceTamatea
Reputation Top 1%
Laurence Tamatea
Associate Professor at Charles Darwin University Australia. Working with .Net Framework.
24 Snippets  (27th place)
Published
1 Channel
Created
3 Channels
Following
2239 points  (32nd place)
Reputation
Top 5% Publisher
Junior Code Generator
Serious Code Generator
Senior Code Generator
Junior Publisher
Serious Publisher
Senior Publisher
Junior Topic Hub
Junior Trend Maker
Serious Trend Maker
Junior Popular Coder
Junior Autobiographer
Serious Autobiographer
Master Autobiographer
Junior Snip2Coder
Master Famous Coder
Junior Wise Coder

## Recent Snippets See all snippets by LaurenceTamatea

### Square Root Function

Square root of the sum of four parameters
``` <!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<body>

<script>

function simpleMath(a,b,c,d) {

return(Math.sqrt) (4+5+6+7);
}

var q = simpleMath();
</script>

</body>
</html>          ```
;

### Variable Declaration After Function

```  <script>

function sumFunction (a, b) {
return (a+b);
}

var x = sumFunction (4, 2);
document.write (x);

</script>

```
;

### Variable Declaration Before Function

```<script>

var sum = addNumbers (23,2342,23424);
document.write (sum);

function addNumbers (x,y,z) {

var result = x*y*z;

return result;

}

</script>

// or //

<script>

var result = addNumbers (2,3,4);

function addNumbers (a, b, c) {

return (a + b + c);
}

</script>            ```
;

### Object Initialisers

``` <!DOCTYPE html>
<html lang="en">

<title>STANDARD TEMPLATE</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>

</style>

<script>
athletes = {
type: "runners",
country: "American"
//0bject = {property:value, property:value}//
//can have unlimited properties//
};
food = {
type: "dairy",
engergy: "high"
};
</script>

<body>

<div>Standard Index Template</div>

<script>
/*object initializer is faster than a constructor function because it
only uses one line of code*/

/*use when creating one or two objects of the same type. If creating 500
person objects for example, then use the constructor function*/

document.write(athletes.country + athletes.type + " eat " + food.type + " for breakfast. ");
</script>

</body>

</html>
```
;

### Create New Instance of an Object Using This.

```<!DOCTYPE html>
<html lang="en">

<title>STANDARD TEMPLATE</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>

</style>

<script>
function trucks(brand, color) {
this.brand = brand;
this.color = color;
//we are working with this curent object//
//constructor function, is a blueprint for a function//
}

var mechanics = new trucks("Mac", "Blue");
var performance = new trucks("Mercedes Benz", "Silver");

//creating a new instance of an object (unlimited) with two properties//
//variable can be an object too//
</script>

<body>

<div>Standard Index Template</div>

<script>
document.write(mechanics.brand);
document.write(performance.color);

//name of the object and a property that we want to access//
</script>

</body>

</html>             ```
;