Monday, July 18, 2011

JavaScript Exercises - string operation: slice, substr and substring

JavaScript Exercises - string operation: slice, substr and substring

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

function exercise(){

var msg = "Hello http://icancode-4-web.blogspot.com/";
var result = "";
result = "msg.slice(13, 40): " + msg.slice(13, 40) + "\n";
result += "msg.substr(13, 14): " + msg.substr(13, 14) + "\n";
result += "msg.slice(40, 13): " + msg.slice(40, 13) + "\n";
result += "msg.substr(40, 13): " + msg.substr(40, 13) + "\n";
result += "msg.substring(40, 13): " + msg.substring(40, 13) + "\n";

alert(result);
}


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

No comments:

Post a Comment