0
Using JavaScript with an External File
You want to create a webpage where clicking a button displays a greeting message. The logic for the greeting is written in an external JavaScript file named app.js. How would you link the JavaScript file to your HTML document? Select the correct HTML code to include the app.js file in your webpage. Options: 1. <link href="app.js"> 2. <script src="app.js"></script> 3. <javascript src="app.js"></javascript> 4. <script href="app.js"></script>
2 ответов
+ 3
What's your guess? (I assume you don't know the answer)
+ 2
The second option is right. To link a JavaScript code to your website and be more organized, you have to use the same script tag as the regular, and use the location of the file "app.js" followed by the src attribute. (The value of the attribute)
The other options are wrong, because:
1. The <link> tag is used to link files such as a CSS stylesheet to your website, and not scripts.
3. <javascript> is not a valid HTML tag.
4. The "href" attribure inside the <script> tag cannot be used for linking a script. You may use the "href" attribute in a <link> tag, as I explained earlier. In a script tag you can use the "src" attribute to specify the source of the script.
The tag should be places in your HTML <head> section.