Saturday, April 21, 2012

Javascript Exercise - String, indexOf() and charAt()



<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mobile-Web-App: Javascript Exercise - String, indexOf() and charAt()</title>
<script>

function test(){
var s = 'Mobile-web-App';
info = "<p>s = 'Mobile-web-App'</p>"
 + "<p> s.indexOf('-') " + s.indexOf('-') + "</p>" 
 + "<p> s.indexOf('-A') " + s.indexOf('-A') + "</p>"
 + "<p> s.indexOf('x') " + s.indexOf('x') + "</p>"  
 + "<p> s.chartAt(0) = " + s.charAt(0) + "</p>" 
 + "<p> s.chartAt('3') = " + s.charAt('3') + "</p>"
 + "<p> s.chartAt(-1) = " + s.charAt(-1) + "</p>"
 + "<p> s.chartAt(20) = " + s.charAt(20) + "</p>";

document.getElementById("prompt").innerHTML=info;
}

</script>
</head>
<body onload="test();">
<h1>Mobile-Web-App: Javascript Exercise - String, indexOf() and charAt()</h1>
<div id="prompt"></div>
</body>
</html>


No comments:

Post a Comment