Sunday, August 28, 2011

Javascript Exercise: Check if the browser support canvas

We can use the code document.createElement('canvas').getContext to check if the browser support HTML5 canvas feature. If the browser support HTML5 canvas feature, it return true, otherwise return false.

example:

Javascript Exercise: Check if the browser support canvas

<!DOCTYPE html>

<html>
<head>
<title>JavaScript Exercise</title>
<script type="text/javascript">

function CheckCanvas(){

if(document.createElement('canvas').getContext){
alert("OK. Your browser support canvas");
}else{
alert("Sorry! your brwser doesn't support canvas");
}

}


function htmlonload(){
CheckCanvas();
}
</script>
</head>
<body onload="htmlonload();">
JavaScript Exercise
</body>
</html>




Friday, August 5, 2011

Javascript Exercise: Math.round(), Math.round(), Math.ceil() and Math.floor()

example:
Javascript Exercise: Math.round(), Math.round(), Math.ceil() and Math.floor()

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Exercise</title>
<script type="text/javascript">

function exercise(){
var result = "";
result += "Math.round(1.4) = " + Math.round(1.4) + "\n";
result += "Math.round(1.5) = " + Math.round(1.5) + "\n";
result += "Math.ceil(1.5) = " + Math.ceil(1.5) + "\n";
result += "Math.floor(1.5) = " + Math.floor(1.5) + "\n";
alert(result);
}


function htmlonload(){
exercise();
}
</script>
</head>
<body onload="htmlonload();">
JavaScript Exercise
</body>
</html>


Wednesday, August 3, 2011

JavaScript: Math.random()

Get a random number between 0 and 1

example:

Math.random()

Tuesday, August 2, 2011

Google Data Java Client Eclipse Plug-in


Kunal Shah walks through how to install and use the Eclipse Plug-in for developers using the Java Client Library for Google Data APIs.

JavaScript: Math.max and Math.min

Math.max and Math.min return the maximum and minimum from a list of numbers.

Example

Math.max(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

Math.min(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)