Page 1 of 1

JavaScript 1 - "Hello World" and script tags Rate Topic: ***** 1 Votes

Replies To: JavaScript 1 - "Hello World" and script tags

#2 maniacalsounds  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 469
  • Joined: 27-June 10

Posted 14 August 2010 - 12:11 PM

As you know, html divides a page up into two main sections. These two sections are known as the head and body sections. The head section (so far) has been used to indicate styling, such a Cascading Style Sheets (CSS), and other less-notable factors that aren't shown on the page. In the body section, you put the actual "meat" of the page, the content. Within the body, you can code images, text, and even animations and videos into the webpage to be shown. The basic premise of this tutorial will be as follows:
  • The head section is used to put things not immediately shown on the page.
  • The body section is used to put the things immediately shown on the webpage when loaded.

Well, in Javascript this is not always the case. In Javascript, code in the head section can be automatically activated. However, this is not always the case. For now, we will put Javascript in the body section to make it easier when learning. So, draw up a basic webpage that shows nothing, like such:
<html>
<head>
</head>
<body>
</body>
</html>


Now, let me explain something:
document.write();

document.write() is a function of Javascript. In Javascript you have "objects", and "functions." To keep it simple now, "document" is the object, and "write()" is a function.
Spoiler

"Document" is the object, which represents the entire webpage. So, in other words, the webpage is a "document." Now, you can probably take a pretty good guess as to what write() is, but I shall tell you anyway. "write()" is a function that will "write" text onto the document, the webpage. Now, in order to tell document.write() what to type on the screen, you'll have to insert quoation marks inside the parentheses and type whatever you want inside of them. For this example, we'll use "Hello World." Try typing up the Javascript code that it will write "Hello World."
Completed Javascript code:
Spoiler

Now that you have that code, we don't know exactly where to put it. In Javascript ALL (so far) code goes inside script tags. For script tags, type the following:
<script type="text/javascript"></script>

As you may have noticed, the javascript script tags are very similiar to the style tags in CSS:
<style type="text/css">CSS</style>

Now that you know what script tags are, it's only logical that we put our Javascript in the script tags, and then insert that into the body sections, as planned. Please try to do that now.
The correct answer:
Spoiler


If you understand this, you can advance to Javascript 2 - Functions and Event Handlers.
~Taken from my Javascript blog.
Was This Post Helpful? 4
  • +
  • -

#3 upri5ing5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-January 11

Posted 03 February 2011 - 02:29 PM

Thanks this is pretty cool. i have a very basic understanding of html, now I'm working for a very basic version of java script
Was This Post Helpful? 0
  • +
  • -

#4 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Posted 14 July 2011 - 02:08 PM

The reputation on this tutorial is strange.

+ systemlordbaal
+ systemlordbaal
- Harlen
+ ahamedirshad123


Yet, it's at -1. Does not compute!

I'll give a thumbs up for the well written tutorial though.
Was This Post Helpful? 0
  • +
  • -

#5 maniacalsounds  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 469
  • Joined: 27-June 10

Posted 20 July 2011 - 07:04 PM

Haha, I was thinking that too. Infact, I've only had two negative reputations of all time, and this was one of them. Another one was for "giving answers for homework."

Silly me. :P

But thanks for the rep :)
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,581
  • Joined: 08-June 10

Posted 13 October 2011 - 06:48 AM

View Postmaniacalsounds, on 14 August 2010 - 09:11 PM, said:

In Javascript you have "objects", and "functions."

and to be precise, "functions" are objects.

a simple demonstration:
// object + function
document.write("Hello World!");

// object + object + function
document.write.call(document, " I am an object.");

// therefore: function = object

Was This Post Helpful? 1
  • +
  • -

#7 JacksonD  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 215
  • Joined: 18-October 11

Posted 21 October 2011 - 07:15 PM

HTML is so easy. I learnt it quickly, But I guess a pretty good tutorial.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1