OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

calling functions in html from external javascript file

  • Thread starter Thread starter monique
  • Start date Start date
M

monique

Guest
This is a simple practical but I'm not sure what I'm doing wrong.
I have the following code in my external javascript file:

Code:
function myname(){
    document.write("Monique");  
}

function welcomeW(name){
    document.write("Welcome " + name + "!");
}

function welcomeR(name){
    return "Welcome " name "!";
}

I added this <script> tag to link to my html file:

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

I tried calling the functions in html using:

Code:
<script> myname(); </script>
<script> welcomeW(Monique); </script>
<script> welcomeR(Monique); </script>

when I wrote the function in html it worked, but in the external file nothing happens.

<p>This is a simple practical but I'm not sure what I'm doing wrong.<br>
I have the following code in my external javascript file:</p>

<pre><code>function myname(){
document.write("Monique");
}

function welcomeW(name){
document.write("Welcome " + name + "!");
}

function welcomeR(name){
return "Welcome " name "!";
}
</code></pre>

<p>I added this <code><script></code> tag to link to my html file:</p>

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

<p>I tried calling the functions in html using:</p>

<pre><code><script> myname(); </script>
<script> welcomeW(Monique); </script>
<script> welcomeR(Monique); </script>
</code></pre>

<p>when I wrote the function in html it worked, but in the external file nothing happens.</p>
 

Latest posts

Top