-2

I have experience with Java and Python and am following along with this tutorial online (https://www.youtube.com/watch?v=W6NZfCO5SIk&t=579s) to learn Javascript. Despite copying and pasting his code (where I have a javascript file called "test.js" and a html file called "test.html", I am unable to have the "Hello world" text displaying in the browser page when it opens. (The title of the page displays correctly, but the "Hello world" text does not display in the page and there is only a blank page).

test.html:

<!DOCTYPE html>
<html lang="en-US">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content = "ie=edge">
    <title>Today's date</title> 
</head>

<body>
    <script src = "test.js">
    </script>  
</body>

test.js:

console.log("Hello world")
jmao
  • 7
  • 1
  • 7
  • 3
    `Hello world` is supposed to get displayed in the console and not on the page itself. Press F12 and check the `Console` tab. – Lain Mar 30 '20 at 12:35
  • The code from that timecode has a big, fat `

    Hello World

    ` in the ``, your code does something completely different. If you watch further, the video creator explains how to look at the console.
    – Chris G Mar 30 '20 at 12:38
  • Then why is it that in the video that I am watching it gets displayed on the page itself when he runs his code? I can see it in the Console tab when I select "Inspect element" but can't see the message display on the page. – jmao Mar 30 '20 at 12:43
  • The HTML `

    Hello World

    ` is parsed and rendered by the browser and thus displayed in big letters in the main window. `console.log("Hello world")` on the other hand writes `Hello World` to the console. But again: your code and the video's do not match, not the filename, not the content at that timecode. It's like you're following two different tutorials. Also: HTML isn't executed. It's not a programming language. HTML defines content and structure, and that is parsed into a DOM object and rendered to the window.
    – Chris G Mar 30 '20 at 12:45
  • You should make sure you pick *one* tutorial, then follow it exactly, to the letter. Experience with other languages means you know that one letter can make a world of difference, HTML and JS are no different. You should also pick different strings maybe, like `

    Huge heading test

    ` and `console.log("I AM CONSOLIO")` so the difference becomes obvious and mistakes are easier to find.
    – Chris G Mar 30 '20 at 12:49
  • Oh yes, thanks. I completely missed the header. I didn't notice that and though that his console.log("Hello world") code was somehow causing the "Hello world" message to display in the page as well as the console. – jmao Mar 30 '20 at 12:51

1 Answers1

0

just press F12 to open your console use alert display it in browser

oh i get you i guess try this <h1></h1>

<body>
    <h1>Hello World</h1>
    <script src = "test.js">
    </script>  
</body>
  • But in the video he doesn't only see it display in the console. He sees it displayed in the browser as well with the same code. – jmao Mar 30 '20 at 12:44