Not able to understand javascript

HI , I just finished my HTML Table tags and started with JAVASCRIPT but i am not been able to understand its coding.

  1. where to write the code?
    2.how to save it with.js
    3 when i save it with .js it dosent open with browser
    4 please help me i am not uderstanding it by reading
    i have gone throught it several times but still havent figured it out .
    PLEASE HELP!!!
1 Like

Hello @pathak.shreyas.s
1st open your text editor and click on open and select a new file
write your javascript code in new file
than press control+s and than save it with file name .js
after that open your .html file using browser
Hope this information is useful for you

1 Like

1.Write your Java Code in the sublime text editor only.
2.Go to save as>>save it with filename.js.
3.Yes,We need to understand that js is something which is used to manipulate the html tags.For example how you use an id to obtain some data(I am not pretty sure about how ID works)But the code written in javascript is a part of the webpage,it manipulates the view of the webpage
Eg:Adding a variable or using a function.

1 Like

hey there.
don’t worry about this. In this program, u will learn HTML, javascript and other supporting items that are required with the Boltiot. but still, u wanna learn more, start the solo-learn app and enroll for a javascript course now and in the end u will get a certificate also.
keep going, my buddy. !!

1 Like

thanks for your reply. but which html file ? i wrote the code and saved it with extension as .js !!! then which html file you are talking about ?

thanks a lot kunjan i will surely try it !!

Thanks a lot!! i understood the first 2 steps of your reply . but i didnt get the 3rd step !! can you please elaborate !! sorry .

1 Like

Hi @pathak.shreyas.s,

The steps is as follows.

  1. First you will create a html file for example index.html.
  2. Then you create a javascript file with .js extension in the same folder where you have created the index.html. For example myjavascript.js
  3. Link your javascript code in html file https://www.w3schools.com/tags/att_script_src.asp
  4. And then you open your html file in browser. (Chrome, Mozila Firefox etc.)
  5. Once you open the html file is will automatically execute the javascript cod also.

For example

myjavascript.js file has the below code.

alert("This alert is coming from javascript file")

then your index.html will have the below code.

<!DOCTYPE html>
<html>
<head>
	<script src="myjavascript.js"></script>
</head>
<body>
Body content
</body>
</html>
1 Like

Thanks a lot Rahul. Can please provide me an example of JavaScript code also. like you provided for html.

Hi @pathak.shreyas.s

alert("This alert is coming from javascript file") is part of the javascript file. https://www.w3schools.com/jsref/met_win_alert.asp

Do let me know in case you need any other information.

i tried it i am not getting this message on my web page !!

my HTML FILE NAME :-INDEX.HTML

Body content

MY JAVASCRIP FILE NAMED:-javascript.js.htc
alert(“This alert is coming from javascript file”)

i have saved both codes in same folder

  • when i open my web site its not showing this message

my INDEX.HTML FILE

Body content

Hi @pathak.shreyas.s,

Sorry i forgot to close <script> tag in html. I am editing the html code in the previous message.

OK NO ISSUE . please send me the update code again

@pathak.shreyas.s

<!DOCTYPE html>
<html>
<head>
	<script src="myjavascript.js"></script>
</head>
<body>
Body content
</body>
</html>

its the same code !! what the diffrence ?

Hi @pathak.shreyas.s,

Check this link in your code <script src="myjavascript.js"></script>

Hello @pathak.shreyas.s
you have to make 2 files. one is .js file and second is .html file
and you have to run the .html file in browser for see your webpage.
Hope this information is useful for you.

i have made 2 separate codes as follows 1)code for HTML save with my-webpage.html
2)js code for javascript save with my-javascript.js.htc
save them both in same folder . but still i am not getting the rrodesire output.
opened my html code in web browser (GOOGLE CHROME)and then right clicked it and selected inspect and then console. but it showing me this message "fail to load resource: net::ERR_FILE_NOT_FOUND