Last active
August 29, 2015 14:02
-
-
Save peterchappell/bd6c26858e2042bde78e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 1: First JavaScript snippet (Hello World Button) --> | |
<button id="mybutton">Click me</button> | |
<script> | |
$(document).ready(function() { | |
var button = document.getElementById("mybutton"); | |
button.addEventListener("click", function(event) { | |
alert("Hello World"); | |
}); | |
}); | |
</script> | |
<!-- 2: Some JavaScript variables to play with --> | |
<script> | |
var greeting = "Hello"; | |
var counter = 0; | |
var yes = true; | |
var no = false; | |
var array = [1,2,3]; | |
var object = { | |
firstName: "Peter", | |
lastName: "Chappell" | |
} | |
</script> | |
<!-- some example JavaScript --> | |
<script> | |
// a condition | |
var count = 1; | |
if (count < 5) { | |
alert('you have less than 5'); | |
} | |
// a for loop | |
for (var i = 0; i < 5; i = i++) { | |
console.log("attempt " + i); | |
} | |
// a while loop | |
var counter = 0; | |
while (counter <= 5) { | |
console.log('do something... '); | |
counter ++; | |
} | |
// a function | |
function sayHello(name) { | |
alert('Hello ' + name); | |
} | |
sayHello('Pete!'); | |
</script> | |
<!-- 3: The button example using JQuery --> | |
<script> | |
$(document).ready(function() { | |
$('#mybutton").click(function() { | |
alert ('Hello World!); | |
}); | |
}); | |
</script> | |
<!-- 4: PHP Hello World --> | |
<p><?php echo 'Hello World!' ?></p> | |
<!-- 5: Looping in PHP --> | |
<?php $products = array('calculator', 'pencil', 'pad', 'abacus') ?> | |
<?php | |
foreach ($products as &$product) { | |
echo '<li>' . $product . '</li>' | |
}?> | |
<!-- 6: Looping through a structure in PHP --> | |
<?php | |
$menuItems = array( | |
array('home', 'index.php'), | |
array('about', 'about.php'), | |
array('contact', 'contact.php') | |
); | |
?> | |
<ul> | |
<?php | |
foreach($menuItems as $menuItem) { | |
echo '<li><a href="' . $menuItem[1] . '">' . $menuItem[0] . '</a></li>'; | |
} | |
?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment