/    Sign up×
Community /Pin to ProfileBookmark

Can I Use Either Number 1 or Number 2 when coding Javascript?

[QUOTE]

Number 1 and number 2 shows the same result in the browser. I am new to JavaScript I am wondering if the first code is also correct, I code it that and my browser displays the same result as my second code does.

[/QUOTE]

[QUOTE]

This is Number One

[/QUOTE]
[code=html]
<script language =”javascript” type=”text/javascript”>

var adultAnimal;
var youngAnimal;

adultAnimal =”Horse”;
youngAnimal =”Ponny;

document.write(adultAnimal+ ” : ” +youngAnimal);

</script>
[/code]

[QUOTE]

This is Number Two

[/QUOTE]
[code=html]
<script language =”javascript” type=”text/javascript”>

var adultAnimal;
var youngAnimal;

adultAnimal =”Horse”;
youngAnimal =”Ponny”;

document.write(adultAnimal);
document.write(” : “);
document.write(youngAnimal);
document.write(” : “);

</script>
[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@rootMay 26.2016 — You don't use document write.

You update a DOM element like an input, text area, ul,li,p and div tags as well as hidden elements by inserting or creating or modifying an existing DOM element.

The easiest is to update an input or textarea in a form.

You only need &lt;script&gt; and not the &lt;script language ="javascript" type="text/javascript"&gt; and remember when coding, use [code=html]<!DOCTYPE html>[/code] to denote that your looking at the browser rendering as HTML5 and not something else and that DOCTYPE is all uppercase.
×

Success!

Help @web90 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.17,
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,
)...