Sample source 3) JavaScript basic document structure (built-in functions)
- First, a quick recap of last time,,, -
break statement: when the initial condition is met but you want to break out (with an additional option). e.g. forced exit
continue statement: when a separately added condition matches, skip the condition and run the next one.
- A quick word on built-in functions,,, -
User-defined function: a function defined by the user
Built-in function: features of JS :: eval (recognizes an expression string / character as a number), isNaN(), Number(), String(), parseInt (string to integer)
* "10px" VS. "px10" = if the letters come first, it's recognized as a string.
Example)
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko"> |
|
|
|
<head> |
|
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" /> |
<title> Recap / built-in functions. </title>
<script type="text/javascript">
//<!CDATA[
document.write( "First, a recap example of built-in functions. " + "<br />");
var p="10px";
document.write(parseInt(p)+"<br />");
var n,m;
n="script";
m="px10";
document.write(parseInt(n)+"<br />");
document.write(parseInt(m)+"<br />");
document.write(isNaN(m)+"<br />");
document.write(isNaN(p)+"<br />"+"<br />"+"<br />");
document.write( "The new example starts with a popup. " + "<br />");
var tel_num=prompt("Enter your phone number without dashes","enter here");
//alert(tel_num);
if (isNaN(tel_num))
{
alert("Please enter numbers only.");
}else{
document.write("The phone number you entered is: " + tel_num);
}
//]]]]>
</script>
</head>
<body>
</body>
</html>
