Professional Documents
Culture Documents
ICT Department
ICT Department
Grade 10
Calling A Code In JavaScript
Calling java script code by using Button command:
To execute java script statements inside <script></script>
FUNCTION:
It’s a set of commands that will be executed when you call it.
Creating a function:
1.Write the function and then write its name that should refer to its job.
Activity
Design a web page and create a function when you call it .
It will display a message box "Arabic public of Egypt" by following
these steps:
Write the code in notepad and save it with the extension .html
<html>
<head><title>call function</title></head>
<body>
<input type="button" onclick="country()" value="click me">
<script>
function country()
{
alert("Arabic public of Egypt");
}
</script>
</body>
</html>
ICT Department
Grade 10
3. The message box will display the text that was written in the text
box.
Activity
Design a web page like the previous figure and do the following:
ICT Department
Grade 10
Create new word pad file.
<html>
<body>
<form name="form1">
<input type="text" name="t1">
<input type="button" onclick="country()" value="click me">
</form>
<script>
function country()
{
alert (form1.t1.value);
}
</script>
</body>
</html>
N.B:
ICT Department
Grade 10
Give the name form1 to the form <form> by using the name
property.
Give the name t1 to the text box by using the name property.
Remember that:
{
If (condition)
Code (that will executed if condition come true)
}
true the code that written between the two brackets will be
executed, and in case of condition not true code will not executed.
ICT Department
Grade 10
Activity:
Design a webpage contains a form, and in the form there will be:
1- Text box
Code:
<html>
<body>
<form name="form1">
<input type="text" name="t1">
<<input type="button", value="sum", onclick="country()"
</form>
<script>
function country()
{
if (form1.t1.value>=50)
{
Alert("success");
}
</script>
</body></html>
ICT Department
Grade 10
Data Types
Numbers:
All JavaScript numbers are stored in the computer memory ,Numbers can be
Example:
// With decimals:
let x1 = 7.5;
ICT Department
Grade 10
// Without decimals:
let x2 = 16;
Strings: A string (or a text string) is a series of characters like "John Doe".
Strings are written with quotes. You can use single or double quotations
Example
Example
let x = 5;
let y = 5;
let z = 6;
(x == y) // Returns true
(x == z) // Returns false
ICT Department
Grade 10
Undefined
BigInt
› JavaScript BigInt is a new data type (ES2020) that can be used to store
Number.
› Example:
› let x = BigInt("123456789012345678901234567890");
› Object:
== equal to
!= not equal
Logical operators
values.
operators
(x == 5 || y == 5)
|| or
is false
Note: The web browsers used to view the saved document must be
determined.
Color :
This code will be viewed using Google Chrome, and saved with
extension .htm .
<html>
<body>
<form>
choose your color
<br>
<input type="color">
</form>
</body>
</html>
Date:
Enable user to enter date in calendar window.
To add date box to t webpage use the following code:
<html>
<body>
<form>
choose your Birthday date
<br>
<input type="date">
</form>
</body>
</html>
ICT Department
Grade 10
Number:
<input type="number">
This code will be viewed using Google Chrome and Firefox, and
saved with extension .htm .
Activity: design a form that contains a number box to be used in
enter numeric values from 1: 20
Code:
<html>
<body>
<form>
enter value between 1 to 20
<br>
<input type="number" min="1" max="20">
<input type="submit">
</form>
</body>
ICT Department
Grade 10
</html>
Notes:
o The value typed in the number box, then click "submit query"
button.
HTML audio tag is used to define sounds such as music and other
audio clips.
<audio controls>
<source src="koyal.mp3" type="audio">
Your browser does not support the html audio tag.
</audio>
Attribute Description
Loop It specifies that the audio file will start over again,
every time when it is completed.
Attribute Description