Feriana High School 4SI
JavaScript Series
Exercise No. 1:
Write the code for an HTML file that allows entering three grades (DC1, DC2, DS) and then calculates and displays the
average.
Exercise No. 2:
Write the code for an HTML file that allows entering the month number and the year, then displays the number.
of days.
Exercise No. 3:
Write the code for an HTML file that displays the multiplication table of an integer between 1
and 10.
Exercise No. 4:
Redo exercise number 1 using a functionAverage, address all possible placements of a
function:
Between <BODY> and </BODY>
Between <HEAD> and </HEAD>
Exercise No. 5:
Write the code for an HTML file that calculates and displays the square of a number entered from the keyboard.
Exercise No. 6:
Write the code for an HTML document titled 'Calculation', containing an input box that allows you to enter a
operation to calculate, a button (=) to display the result and an answer area.
Add a hyperlink to display the result.
Mr. T. Rhimi [Link] AS. 2009-2010
Feriana High School 4SI
Exercise No. 7:
Create an HTML file titled 'Formation', containing the following form:
Clicking the 'Send' button of type submit calls a function 'Verif' written in JavaScript and
which allows to verify the following conditions:
The fields Name and First Name, ID card and Email Address must be non-empty.
The CIN field contains only 8 digits from 0 to 9.
The email address must contain the character @.
The Secondary level is selected by default.
You can choose a maximum of two training modules.
If the previous conditions are met, the following message will be displayed: "Registration completed !!"
The 'Cancel' button allows you to clear all the fields of the form.
Mr T. Rhimi [Link] AS. 2009-2010
Feriana High School 4SI
Correction
Exercice n°1 : Moyenne
<html>
<head><title>Moyenne</title></head>
<body>
<script language="JavaScript">
dc1=Number(prompt("Donner la note du dc1 : ",""));
dc2=Number(prompt("Donner la note du dc2 : ",""));
ds = Number(prompt("Enter the grade of the ds: ", ""));
moy=(dc1+dc2+2*ds)/4;
the average is :
</script>
</body>
</html>
Exercise No. 2: Number of days.
<html>
<head><title>Jours</title></head>
<body>
<script language="JavaScript">
m=Number(prompt("Enter the month number", ""));
a=Number(prompt("Enter the year number",""));
switch(m)
{
case 1 : case 3 : case 5 : case 7 : case 8 : case 12: j=31; break;
case 4 : case 6 : case 9 : case 11 : j=30; break;
case 2 : if (a%4==0) j=29; else j=28; break;
}
alert("The number of days is: " + j);
</script>
</body>
</html>
Exercise No. 3: Table
<html>
<head><title>Table</title></head>
<body>
<script language="javascript">
n=Number(prompt("Enter an integer: ", ""));
for(i=0;i<=9;i++)
[Link]("<br>"+n+"*"+i+"="+n*i);
</script>
</body>
</html>
Mr T. Rhimi [Link] AS. 2009-2010
Feriana High School 4SI
Exercise No. 4: Function
<html>
Average
<script language="JavaScript">
function average(dc1, dc2, ds)
{moy=(dc1+dc2+2*ds)/4; [Link]("la moyenne est : "+moy); }
</script>
</head>
<body>
<script language="JavaScript">
dc1=Number(prompt("Donner la note du dc1 : ",""));
dc2=Number(prompt("Donner la note du dc2 : ",""));
ds = Number(prompt("Enter the grade of the ds: ", ""));
average(dc1,dc2,ds);
</script>
</body>
</html>
Exercise No. 5: Square
<html>
<head><title>CARRE</title></head>
<body>
<script language="JavaScript">
function square()
var c=[Link]*[Link];
alert("The square of " + [Link] + " is " + c); }
</script>
<FORM name="f">
<INPUT type="text" name="nb" size="4">
<INPUT type="button" value="Calculer le carré" onclick="carré()">
</FORM>
</body>
</html>
Exercise No. 6: Calculation
<html>
<head><title>Calculation</title>
<script language="JavaScript">
function result()
var a=[Link];
var b=eval(a);
[Link]=b; }
</script>
</head>
<body>
<form name="f">
<input type="text" name="zt1">
<input type="button" value=" = " onclick="resultat()">
<input type="text" name="zt2"><br>
<a href="#" onclick="result()">see</a>
</form>
</body>
</html>
Mr. T. Rhimi [Link] AS. 2009-2010
Feriana High School 4SI
Exercise No. 7: Training
<html>
FORMATION
<script language="JavaScript">
function verify()
{ if([Link] == "") { alert("Veuillez taper votre nom et prénom!"); return false; };
if([Link] == '') { alert('Please enter your CIN!'); return false; };
var v = 1;
var size = [Link];
for(i=0;i<size;++i)
if([Link](i) < "0" || [Link](i) > "9" || size != 8) v = -1;
if(v == -1) {alert("The number of your ID card is incorrect!"); return false; }
if([Link] == "") { alert("Please enter your email address!"); return false; }
if([Link]('@') == -1) { alert("Incorrect email address!"); return false; }
size=[Link];
var n=0;
for(i=0;i<length;i++){if ([Link][i].selected){n+=1};}
if (n==0) {alert("Please choose a training module!"); return false;}
if (n>2) {alert("Please select a maximum of 2 choices!");return false;}
}
</script>
</head>
<body bgcolor="#FFCCCC">
<h2 align="center"><u>REGISTRATION</u></h2><br>
<form name="f" action="[Link]" method="post" onSubmit="return verif()">
<pre>
Nom et Prénom * : <input type="text" size="30" name="nom"> <br><br>
CIN * : <input type="text" size="10" name="cin"><br><br>
Adresse e-mail * : <input type="text" size="30" name="email"> <br><br>
Level:
Secondary
University Other
Training modules:
<SELECT name="list" multiple size="3" >
Office Automation
IT and Computer Networks.
TIC
Programming
</SELECT><br><br>
(*) Required fields
<input type="submit" value="Envoyer"> <input type="reset" value="Annuler">
</pre>
</form>
</body>
</html>
Mr T. Rhimi [Link] AS. 2009-2010