Unit V - Lesson 1

6.1.1. JavaScript, the language

(a) One can use JavaScript to build a youtube like web application
(c) One of the ways JavaScript is used in the server side, is by using Node.js runtime
(d) It is possible to download a file from the Internet using JS

6.1.2. Including JS in HTML

(a) Both inline scripts & external scripts can be included using the <script> element
(b) Inline scripts have the JS code included as the <script> element's text content
(c) External scripts allow having the JS code in different files from the HTML. Therefore, it is possible to reuse the same script in multiple web pages.
(d) The following is how the example snippet shown will appear in a browser where JavaScript is disabled:

This page requires JavaScript to be enabled to become awesome

6.1.3. Inline script

<!doctype html>
<html>
	<body>
		<button type="button" onclick="alert('Hello')">Say hello</button>
	</body>
</html>

6.1.4. Inline script

<!doctype html>
<html>
	<body>
		<script>
			var fruit = 'Apple';
		</script>
		<button type="button" onclick="alert(fruit)">Click here</button>
	</body>
</html>

6.1.5. External script

<!doctype html>
<html>
	<body>
<script src="user.js"></script>
		<script>
			var fruit = 'Apple';
		</script>
		<button type="button" onclick="alert(fruit)">Click here</button>
	</body>
</html>

6.1.6. Where to put script tags?

(a) By moving the inline script to be the final child of the body element, it will work as expected showing the text Hello from CodeTantra as a heading.
(c) By moving the inline script to be the child of the h3 element, it will work as expected, showing heading.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.