working on it ...

Filters

Sort by

Found 21 snippets

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>

document.write (sum);

var result = x*y*z;

return result;

}

</script>

// or //

<script>

function addNumbers (a, b, c) {

return (a + b + c);
}

</script>            ```

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>             ```

Strength Length

Objects have properties and methods using the dot separator
``` <!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>

<body>

<div>OBJECT ORIENTED PROGRAMING</div>

<script>

//dat with its own properties and methods//

var passenger = "I am passenger 3b";

passenger.length;
document.write (passenger.length); //length is a property of the passenger object//

//document is an object and write is a method//

</script>

</body>

</html>
```

onMouseOver & onMouseOut

Basic even handlers
```<!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>

<body>

<div>On Mouseover</div>

<script>
//you can also use onMouseOut for when you take your cursor away from the link//

</script>

</body>

</html>```

Event Handler onClick

``` <!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>

<body>

<div>Event Handlers</div>

<form>

</form>

<script>
//end the js statment with a semi-colon//
//double quotation markets for attributes and single for JS//
//don't need to put the script between the script tags.//

</script>
</body>

</html>                       ```

Do While Loop

Runs the code until the condition is met.
``` <!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>

<body>

<div>Do While Loop</div>

<script>
//runs the code until it gets to the condition which is eequal to or less than 30.//

var passengers=12; //if this var value was higher than the condition it will run once first//

do {
document.write (passengers + " There are more and more passengers? <br />");
passengers++;
}  while (passengers<=30);

</script>

</body>

</html>           ```

While Loop

``` <!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>

<body>

<div>Standard Index Template</div>

<script>

var passengerlist=1;

while (passengerlist<99) {
document.write("The passenger list is long today <br />");
passengerlist++; //while passengers is less than 99 it will run the code//
}

</script>

</body>

</html>          ```

For Loop

``` <!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>

<body>

<div>Standard Index Template</div>

<script>

for (x=0; x<10; x+=2) {
document.write("I am printed out five times<br />");
/*for takes three conditions in the variable. Start point, end point and
how much the value increments by. Here it is 2. You could go x++*/
}

</script>

</body>

</html>```
• Public Snippets
• Channels Snippets