last day (15 days later) » 

9:31 AM
-2
Q: I see only my javascript code instead of result

DavidczWhy I see only my javascript code instead of result? At first I tried this: javas.js: <script type="text/javascript"> alert('Hello, world!'); </script> then I removed < script > javas.js: alert('Hello, world!') then I tried js code in html file and with Hello World output: javas.html: <html>

 
No, it is .js file
I deleted it but result is the same.
@DBS I tried this, see only code : <html> <body <script type="text/javascript"> alert('Hello, world!'); </script> </body> </html>
 
"I tried this, see only code :" Where did you try this? Is this still in a .js file or a .html file?
 
Now html. After that I wrote same code like there: youtu.be/0YFtEZaN6wU?t=265, But my result is only js code again.
 
I would suggest that you update your question detailing absolutely everything you have tried. Make sure you describe how you're viewing the files, what the filenames are, any little detail that might be relevant. You never know, your question may even get reopened!
Could you show how you were including javas.js in your HTML too.
But as @Ivar stated, you appear to have a missing closing > on your body tag.
 
You are genius :-)
But I think that js code shold run in pure .js file, like @DBS wrote that I don´t neeed <script> in .js file.
Is it possible to run .js file without html in browser?
 
9:33 AM
Yes, it's possible to run JS in browser without HTML but it has to be run from the browser's address bar on a single line prefixed with javascript: i.e. javascript:alert('Hello, world!').
 
javascript: i.e. javascript:alert('Hello, world!')
I wrote that but still see code only.
 
No, just "javascript:alert('Hello, world!')"
Unfortunately code isn't quite as obvious in these discussions.
Stick that in the browser's address bar and it should pop up the alert
 
<script type="text/javascript">
javascript:alert('Hello, world!')
</script>
javascript:alert('Hello, world!')
I tried this with <script> and without also
 
No, you were asking how to run JS in the browser without HTML. You can only do that from the address bar!
The <script> tag is a HTML tag and would need to be placed in an HTML file that is opened by the browser.
 
javascript:alert('Hello, world!')
This should be wrotten to address bar?
 
9:45 AM
Yes, if you want to run JS without HTML
 
But it find google rersults
 
Otherwise you need a HTML page with a <script> tag that either links to the JavaScript file or wraps your JavaScript.
 
Ok
 
Then notice that when you paste it in address bar there are 2 options in the dropdown. One for searching what you type and another to "visit the site".
Looks like this in Chrome:
Make sure you pick the right option.
Might be worth you checking out MDN's JavaScript basics
 

last day (15 days later) »