Q2 MODULE2 G11 .NET PROG MangaldanNHS
Q2 MODULE2 G11 .NET PROG MangaldanNHS
11
TVL-ICT
PROGRAMMING .NET TECHNOLOGY
NC III
QUARTER 2 – MODULE 2
II. CONTENT
JavaScript is a lightweight, interpreted programming language. It is designed for
creating network-centric (a depending on the internet) applications. In a nutshell, JavaScript
is a prototype-based scripting language with dynamic typing and first-class function support.
JavaScript borrows most of its syntax from Java, but is also influenced by Awk, Perl, and
Python. JavaScript is case-sensitive and white space-agnostic.
<script> element
The primary method of inserting JavaScript into an HTML page is via the <script> element.
This element was created by Netscape and first implemented in Netscape Navigator 2. It was
later added to the formal HTML specification.
<script>
//JAVASCRIPT CODE
</script>
Hello World using JavaScript
<html>
<body>
<script language = "javascript" type = "text/javascript">
document.write("Hello World!")
</script>
</body>
</html>
Comments
JavaScript allows single line or multiple line comments. The syntax is similar to Java:
1
LO 2.2 Declare variables in JavaScript
Variables
A variable is essentially a named value, and as the name implies, the value can change at
any time.
A JavaScript variable name must start with a letter, underscore (_), or dollar sign ($);
subsequent characters can also be digits (0-9). As JavaScript is case sensitive, letters
include the characters A through Z (uppercase) and the characters a through z (lowercase).
Assignment Operator
The equal sign (=) is an "assignment" operator, not an "equal to" operator.
var x;
x = x + 10
2
<h1> Web Page</h1>
<p> Paragraph One</p>
<p id="text"></p>
<script>
document.getElementById("text").innerHTML = 5 + 6;
</script>
</body>
</html>
Using document.write()
<!DOCTYPE html>
<html>
<body>
<h1>Test Web Page</h1>
<p>Paragraph One.</p>
<script>
document.write(4 + 6);
</script>
</body>
</html>
Using Alert()
<!DOCTYPE html>
<html>
<body>
<h1>Test Web Page</h1>
<p>Paragraph One.</p>
<script>
alert(“Hello World”); //display hello world message
alert(4 + 6); // display the sum.
</script>
</body>
</html>
III. EXERCISES
A.
Direction: Complete the source code to display “My First JavaScript
Program” into a pop-window using alert() method.
<html>
<head>
<title> Basic JavaScript </title>
<script type=”__________”>
3
______________
</______________>
</head>
<___________>
</____________>
</html>
B. JavaScript ProgSample
a) Declare variable x.
b) Initialize x to five.
c) Declare variable y.
d) Initialize y to ten.
e) Display the sum of x and y.
IV. SUMMATIVE
Write all your answers in the ANSWER SHEET attached with this module
4
3. Write the syntax of JavaScript single line comment “My first JavaScript”.
____________________________________________
4. Write the syntax to:
a. Declare a variable “name”. _____________________
b. Declare a variable “section”. ______________________
c. Declare a variable “gender”_______________________
d. Assign the value “Melo” to variable “name”. __________________
e. Assign the value “ICT1” to variable “section”. ____________________
f. Display text “Hello Senior High” using document.write().
_______________________
g. Display text “Web programming” in the element <div id= “msg”> using
innerhtml. _________________________
h. Display alert box with message “Hello SHS!”. ________________________
B. Displaying a data in JavaScript can be done in different ways using pre-defined
method. If you are going to build a website, what method should you use to warn
the user to input data? Select two methods below and explain your answer.
a. alert()
b. document.write
c. console.log
d. document.getElementBy(Id)
5
NAME: ___________________________________ SCORE: ________
SUBJECT TEACHER: _______________________ GRADE/SECTION: ________
A.
1. ______________________
2. ______________________
3. ______________________
a. ___________
b. ___________
c. ___________
d. ___________
e. ___________
f. ___________
g. ___________
h. ___________
B.
6
ANSWER KEY
EXERCISES
A.
<html>
<head>
<title> Basic JavaScript </title>
<script type=”text/javascript”>
B.
a. var x;
b. x=5;
c. var y;
d. y=10;
References: