/    Sign up×
Community /Pin to ProfileBookmark

Stuck on JavaScript Tutorial

I”m trying to learn JavaScript, and I’m Stuck right out of the gate. In tutorial number 3 here:

[url]http://www.htmlgoodies.com/primers/jsp/hgjsp_3.html[/url]

my problem is with this section here:

[QUOTE]

It would appear from the script that again “getSomething()” is a method of “document”. Not so. The method of “document” is “write”. “getMonth()” is actually a method of the object Date. Again, look up at the script. “Date” is set aside in the command:

RightNow = new Date();

Here I am setting aside an object for the method getMonth() to work on. The format is the same each time you use dates and times. You must create an object. My object is titled RightNow.

[/QUOTE]

if RightNow is an object created by the writer of the script, what is Date()?

and further this section says:

[QUOTE]

The problem is that these items are only methods. They need an object to act on and the document object won’t do it…

[/QUOTE]

but the fifth line of the script contains “document.write” anyway, so what does he mean?

If their are any good beginner books out there, i’m all ears.

thanks!

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayFeb 10.2004 — The line:

RightNow = new Date();

creates RightNow as an object of type Date, and loads the default properties and methods.

As far as good tutorials try this one:

http://www.w3schools.com/js/default.asp
Copy linkTweet thisAlerts:
@oleragFeb 10.2004 — The intent here, most probably, is to introduce the JS Date

object to include initialization of the current date. In

addition, the author expands several of the object's accessor

functions in order to provide a user-defined date format.

The "document.write()" function accepts a string argument

and is used to display the results in a browser window. An

alert, activated via a button, could have been another

approach.
Copy linkTweet thisAlerts:
@BlankRegauthorFeb 10.2004 — Thanks for the replies.

TheBearMay: So, RightNow is an object. and Date() is an Object Type?
Copy linkTweet thisAlerts:
@TheBearMayFeb 11.2004 — Close enough. The Date() is actually a function call that instantiates (creates) the requested object in its image, in this case RightNow. Think of it as an initialization function.
Copy linkTweet thisAlerts:
@BlankRegauthorFeb 11.2004 — Many thanks for the clarifications. so the methods: getDay(), getDate(), getMonth(), getFullYear(), getHours(), getMinutes(), and getSeconds() wont function without first using the function call of Date()?

Sorry if i sound like a broken record, but i want to get the foundation straight before i go to much further.

-reg
Copy linkTweet thisAlerts:
@TheBearMayFeb 11.2004 — Correct. The methods don't exist until the instance of Date() is instantiated. Thus:

getDay(); // generates an error

RightNow = new Date();

getDay(); // also returns an error because we don't reference the object

RightNow = new Date();

RightNow.getDay(); // will return the day of the week
Copy linkTweet thisAlerts:
@BlankRegauthorFeb 11.2004 — You sir, Rock Old-School style. I got it. THANKS!
Copy linkTweet thisAlerts:
@BlankRegauthorFeb 12.2004 — Well, i'm now confused about a point on tutorial 6 found here:

http://www.htmlgoodies.com/primers/jsp/assignment6.html

is this part of the script:
var d = new Date();

var y = d.getFullYear();


var m = d.getMonth() + 1;


var d = d.getDate();

var t = m + '/' + d + '/' + y + ' ';[/QUOTE]


setting up 2 variables called "d"? i didn't think you could have 2 variable with the same name?
Copy linkTweet thisAlerts:
@oleragFeb 12.2004 — Well, JS is "loosely" typed but that's downright greasy. Even

if that is possible, is poor practice and that also means that

the first "d" storage variable (holding the date) could not

be referenced in the scope of function once the other "d"

becomes instantiated.
×

Success!

Help @BlankReg spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...