Rohitz -zust stay here
Rohitz -zust stay here

Reputation: 172

How to change javascript datatype value in html

I have a rt.js file in which var k=1; is written. And i have linked it to my html file ss.html. I want to change k value to 2 and then want to print it.

The code is:

<html>
 <body>
<script type="text/javascript" src="rt.js">
 k=2;
document.write(k);
</script>
</body>
</html>

problem: Now the problem is that its supposed to print 2 but its printing 1 only. can you tell me what should i need to do?

Upvotes: 2

Views: 61

Answers (1)

baao
baao

Reputation: 73251

You need to seperate your <script> tags, like so

<script type="text/javascript" src="rt.js"></script>

and

<script>
k=2;
document.write(k);
</script>

Upvotes: 2

Related Questions