$type=slider$count=4$ico=1$cate=0$rm=0$sn=0$cm=0$show=home$meta=hide

Begining a Java Script

Write your first JavaScript - Learn through examples

JavaScript can be used in two different ways - (1) In the same HTML document, or (2) as a separate JavaScript file which can be linked by many HTML document. You'll use the first way if your script is specific only for one HTML document. But if your same script is used in many HTML documents then the second way of use is best.

JavaScript are included in a <script> tag. The beginning and end of a <script> tag can be written as follows:
<script language="JavaScript" type="text/javascript">
.
.
.
</script>
All your JavaScript then goes inside the above element. Let's start with this basic example.
now = new Date();
localtime = now.toString();
utctime = now.toGMTString();
document.write("<b>Local time:</b> " + localtime + "<BR>");
document.write("<b>UTC time:</b> " + utctime);
The first line of the script creates a new variable now and create a new Date object. Note that every line of code in JavaScript ends with a semicolon ';' so do not forget that. The next two line create two new variable localtime and utctime, and the last two lines is a way to display the variable into the HTML document. The document.write(); function is used to create text or display the variable in the html document.

For this script to work, you'll have to put it inside an HTML document. Just create a simple HTML document and place the above codes in any part of the <body> section. Your complete HTML document would look like this:
<html>
<head>
 <title>My JavaScript</title>
 </head>
<body>
 <h1>Date and Time</h1>
 <p>
  <script language="JavaScript" type="text/javascript">
   now = new Date();
   localtime = now.toString();
   utctime = now.toGMTString();
   document.write("<b>Local time:</b> " + localtime + "<br />");
   document.write("<b>UTC time:</b> " + utctime);
  </script>
 </p>
</body>
</html>
Save the file and open it in your browser to see the effect. We'll talk more about the document.write(); function. This function take any string or variables and display that in the browser. You can just add any string by entering some text inside the parentheses and enclosed with quotations. Example document.write("Hello World!"); - this will display the word Hello World! in your browser.  In the above example, you see a + sign. This operator is used to join the string "<b>Local time:</b> " with the variable localtime and again with the string "<BR>".

In the next tutorial, we'll show you more about variables and functions in JavaScript.

COMMENTS

3/random/post-list
Name

blog,11,chemistry,8,css,1,feature,13,html,5,java-script,2,php-mysql,3,solved-qp,4,spectroscopy,3,technology,5,videos,3,web-design,13,
ltr
item
F Diengdoh.com: Begining a Java Script
Begining a Java Script
Write your first JavaScript - Learn through examples
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixYUxczD2vOP4TY7YVagMyIKc8fApBu5GwLOwzHZrGuAc9iz9cjU27irrsPSh3DabkeXf7Z9eQBDTgYyin_hVEUNZ5yK1RcKuMjHhRvx-l-xPnVqcIsIzsQt6mIlOhAZpjO3ccy7c7ymg/s1600/file6431264266292.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixYUxczD2vOP4TY7YVagMyIKc8fApBu5GwLOwzHZrGuAc9iz9cjU27irrsPSh3DabkeXf7Z9eQBDTgYyin_hVEUNZ5yK1RcKuMjHhRvx-l-xPnVqcIsIzsQt6mIlOhAZpjO3ccy7c7ymg/s72-c/file6431264266292.jpg
F Diengdoh.com
https://www.fdiengdoh.com/2016/01/begining-java-script.html
https://www.fdiengdoh.com/
https://www.fdiengdoh.com/
https://www.fdiengdoh.com/2016/01/begining-java-script.html
true
6372396504026100368
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content