A script written in a separate file is not executed | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

A script written in a separate file is not executed

I created the .html and .js files in the same folder on my smartphone. Everything is as in the lesson, but the script is not executed. Why? What is missing? Я создал файлы .html и .js в одной папке на смартфоне. Всё как в уроке, но скрипт не выполняется. Почему? Чего не хватает?

6th May 2020, 8:12 AM
Сергей Куликов
Сергей Куликов - avatar
10 Answers
+ 4
Сергей Куликов It should work. Are you sure, both the html and js files are in the same folder?
6th May 2020, 8:52 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 1
Hey Сергей Куликов, did you include your script in the html document? Just add the script tag after the body tag! <body> .... </body> <script src="your-js-file-name.js"></script> As long as you don't include the file, it won't work :))
6th May 2020, 8:24 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 1
Сергей Куликов Here is an example : alertBox.js (js file) alert('Hi there, I am running!'); ----------------------- index.html (html file) <html> <head> <!-- Do not include here --> </head> <body> </body> <script src="alertBox.js"></script> <!-- Include the javascript file after the body tag --> </html> Now if you open, index.html in your browser, you'll get 'Hi there, I am running!' as an alert!
6th May 2020, 8:39 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 1
Arb Rahim Badsa, n itstill doesn't work. In the upper code I just tried the script working. Now html is.: <!DOCTYPE html> <html> <head> <title>Page Title</title> <script src="text.js"></script> </head> <body> </body> </html> and it doen't work
6th May 2020, 8:40 AM
Сергей Куликов
Сергей Куликов - avatar
+ 1
ok i'm going to try it now...
6th May 2020, 8:41 AM
Сергей Куликов
Сергей Куликов - avatar
+ 1
Arb Rahim Badsa, it still doesn't work. I'll figure it out later. Thank you for the help.
6th May 2020, 8:51 AM
Сергей Куликов
Сергей Куликов - avatar
0
Arb Rahim Badsa, yes, sure. Everything is like in the lesson. html file: <!DOCTYPE html> <html> <head> <title>Page Title</title> <script>alert("This is an alert box!");</script> </head> <body> </body> </html> js file: alert("This is an alert box!");
6th May 2020, 8:28 AM
Сергей Куликов
Сергей Куликов - avatar
0
stop...
6th May 2020, 8:28 AM
Сергей Куликов
Сергей Куликов - avatar
0
there is no file name. I guess I didn't save it.
6th May 2020, 8:33 AM
Сергей Куликов
Сергей Куликов - avatar
0
Arb Rahim Badsa, yes I'm sure. I am busy now a little, maybe I have a mistake in my code. I'll do it later, thanks.
6th May 2020, 8:55 AM
Сергей Куликов
Сергей Куликов - avatar