You are on page 1of 11

<!

--Shkruani nje skript qe i kerkon perdoruesit te japi


dy numra. Merrni numrat nga perdoruesi, logaritni dhe
shfaqni shumen prodhimin, diferencen dhe pjestimin e
dy numrave.

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var numri1=window.prompt("Numri pare");
numri1=parseInt(numri1);
var numri2=window.prompt("Numri dyte");
numri2=parseInt(numri2);
document.writeln("Shuma
eshte"+(numri1+numri2));
document.writeln("Prodhimi
eshte"+(numri1*numri2));
document.writeln("Diferenca eshte"+(numri1-
numri2));
document.writeln("Pjesetimi
eshte"+(numri1/numri2));
</script>
</head>
</html>

Vlera me e madhe ne nje alert


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var numri1=window.prompt("Numri pare");
numri1=parseInt(numri1);
var numri2=window.prompt("Numri dyte");
numri2=parseInt(numri2);
var numri3=window.prompt("Numri trete");
numri3=parseInt(numri3);
var max;
max=numri1;
if (numri2>max){
max=numri2;{
if (numri3>max)
max=numri3;
}}
alert("Numri me i madh eshte"+max);
</script>
</head>
</html>
Shkruani nje skript qe llogarit katrorin dhe kubin e
numrave nga 0 ne 5.Bejeni tabelen nje rresht te
bardhe nje gri

<!DOCTYPE html>
<html>
<head>
<style>
table tr:nth-child(odd){
background: white;
color:grey;
}
table tr:nth-child(even) {
background: grey;
color:white;
}
</style>
</head>
<body>
<table border="1">
<script>
document.write("<tr><td>Numri</td><td>Katrori</td>
<td>Kubi</td></tr>");
for(var i=0;i<=5;i++){

document.write("<tr><td>"+i+"</td><td>"+(i*i)+"</td>
<td>"+(i*i*i)+"</td></tr>"); }
</script> </table> </body> </html>

Shkruani nje skript qe lexon nje numer integer me 4


shifra dhe percakton nese eshte ose jo palidrome.
Nese numri nuk eshte me 4 shifra shfaqni nje alert
dialog qe tregon problemin. Lejoni perdoruesin te japi
nje vlere te re pasi te keni shfaqur alert dialog.

<!DOCTYPE html>
<html>
<head>
<script>
var numri=window.prompt("Vendosni numrin");
numri=parseInt(numri);
while(numri>9999 || numri<1000){
alert("Number not 4 digits");
var numri=window.prompt("Vendosni numrin");
numri=parseInt(numri);
}
var shifra4=numri%10;
numri=parseInt(numri/10);
var shifra3=numri%10;
numri=parseInt(numri/10);
var shifra2=numri%10;
var shifra1=parseInt(numri/10);
if(shifra4==shifra1&&shifra2==shifra3)
alert ("Number palindrome");
else
alert("Number not palindrome");
</script>
</head>
</html>

Skript qe lexon cfaredo numri dhe


kontrollon nese eshte palindrome
<html>
<head>
<script>
var numri=window.prompt("Vendosni numrin");
numri=parseInt(numri);
var rev = 0;
var n=numri;
while (numri > 0)
{
dig = numri % 10;
rev = rev * 10 + dig;
numri = parseInt(numri / 10);
}
if(n==rev)
alert("Palindrome");
else
alert("Jo palidrome");
</script>
</head>
</html>
Shkruani ne skript qe qe lexon nje numer me kater
shifra nepermjet nje prompt dialog dhe e enkripton
ate sipas nje rregulli. Zevendesoni cdo shifer me modul
10 (shuma e shifres me 7) dhe me pas shkembeni
shifren e pare me te treten dhe shifren e dyte me te
katerten. Me pas shfaqni rezultatin si nje text ne
HTML5.

<!DOCTYPE html>
<html>
<head>
<script>
var numri=window.prompt("Vendosni numrin");
numri=parseInt(numri);
while(numri>9999 || numri<1000){
alert("Number not 4 digits");
var numri=window.prompt("Vendosni numrin");
numri=parseInt(numri);
}
var shifra4=numri%10;
shifra4=(shifra4+7)%10;
numri=parseInt(numri/10);
var shifra3=numri%10;
shifra3=(shifra3+7)%10;
numri=parseInt(numri/10);
var shifra2=numri%10;
shifra2=(shifra2+7)%10;
var shifra1=parseInt(numri/10);
shifra1=(shifra1+7)%10;

var temp;
temp=shifra1;
shifra1=shifra3;
shifra3=temp;

temp=shifra2;
shifra2=shifra4;
shifra4=temp;

alert("Numri i enkriptuar eshte:"+shifra1+shifra2+


shifra3+shifra4);
</script>
</head>
</html>
DEKRIPTIMI

<!DOCTYPE html>
<html>
<head>
<script>
var numri=window.prompt("Vendosni numrin");
numri=parseInt(numri);
while(numri>9999 || numri<1000){
alert("Number not 4 digits");
var numri=window.prompt("Vendosni numrin");
numri=parseInt(numri);
}
var shifra4=numri%10;
numri=parseInt(numri/10);
var shifra3=numri%10;
numri=parseInt(numri/10);
var shifra2=numri%10;
var shifra1=parseInt(numri/10);

var temp;
temp=shifra1;
shifra1=shifra3;
shifra3=temp;

temp=shifra2;
shifra2=shifra4;
shifra4=temp;

shifra1=shifra1+3;
if(shifra1>10){
shifra1=shifra1%10; }
shifra2=shifra2+3;
if(shifra2>10){
shifra2=shifra2%10; }
shifra3=shifra3+3;
if(shifra3>10){
shifra3=shifra3%10; }
shifra4=shifra4+3;
if(shifra4>10){
shifra4=shifra4%10; }
alert("Numri i dekriptuar eshte:"+shifra1+shifra2+
shifra3+shifra4);

</script>
</head>
</html>
USHTRIMI ME TOTALIN E NJE DITE PER PRODUKTET ME
SWITCH CASE
<html>
<head>
<script>
var numriproduktit;
var sasia;
var total=0;
var nentotal;

window.alert("Vendosni numrin e produktit ose shtypni


-1 nese nuk keni me gje per te shtuar");
numriproduktit=window.prompt("Vendosni numrin e
produktit");
numriproduktit=parseInt(numriproduktit);

while (numriproduktit!=-1)
{
switch(numriproduktit)
{
case 1:
sasia=window.prompt("Vendosni sasine");
sasia=parseInt(sasia);
nentotal=sasia*1;
break;
case 2:
sasia=window.prompt("Vendosni sasine");
sasia=parseInt(sasia);
nentotal=sasia*2;
break;
case 3:
sasia=window.prompt("Vendosni sasine");
sasia=parseInt(sasia);
nentotal=sasia*3;
break;
case 4:
sasia=window.prompt("Vendosni sasine");
sasia=parseInt(sasia);
nentotal=sasia*4;
break;
case 5:
sasia=window.prompt("Vendosni sasine");
sasia=parseInt(sasia);
nentotal=sasia*5;
break;
default:
window.alert("E pavlefshme");
break;
}
total=total+nentotal;
numriproduktit=window.prompt("Vendosni numrin e
produktit");
numriproduktit=parseInt(numriproduktit);
}
document.writeln("<p> Totali per nje dite
eshte:"+total+"</p>");

</script>
</head>
</html>

Write a script that uses a form to get the radius of a


circle from the user, then calls the function circleArea
to calculate the area of the circle and display the result
in a paragraph on the page. To get the number from
the form, use the techniques shown in Self-Review
Exercise 9.6.

<html>
<head>
<script type="text/javascript">
function circleArea(x)
{
area=x*x*Math.PI;;
document.writeln("<p> Siperfaqja e rrethit
eshte:"+area+"</p>");
}
</script>
</head>

<body>
<form
onsubmit="return(circleArea(document.getElementById
('rrezja').value));">
<input type="text" id="rrezja" name="rrezja"
value="">
<input type="submit" value="Submit">
</form>
</body>
</html>
Write function distance that calculates the distance
between two points (x1, y1) and (x2,y2). All numbers
and return values should be floating-point values.
Incorporate this function into a script that enables the
user to enter the coordinates of the points through an
HTML5 form. To get the numbers from the form, use
the techniques shown in Self-Review

<html>
<head>
<script type="text/javascript">
function distance(x1,y1,x2,y2){
distanca=Math.sqrt(Math.pow((x2-
x1),2)+Math.pow((y2-y1),2));
document.writeln("<p> Distanca
eshte"+distanca+"</p>");
}

</script>
</head>
<body>
<form
onsubmit="return(distance(document.getElementById
('x1').value,document.getElementById('y1').value,docu
ment.getElementById('x2').value,document.getElement
ById('y2').value));">
<input type="text" id="x1" value="">
<input type="text" id="y1" value="">
<input type="text" id="x2" value="">
<input type="text" id="y2" value="">
<input type="submit" value="Submit">
</form>
</body>
</html>
Write a function multiple that determines, for a pair of
integers, whether the second integer is a multiple of
the first. The function should take two integer
arguments and return true if the second is a multiple
of the first, and false otherwise. Incorporate this
function into a script that inputs a series of pairs of
integers (one pair at a time). The HTML5 form should
consist of two text fields and a button to initiate the
calculation. The user should interact with the program
by typing numbers in both text fields, then clicking the
button.

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function calculate(x,y){
if (y%x==0)
document.writeln("True");
else
document.writeln("False"); }
</script>
</head>
<body>
<form
onsubmit="return(calculate(document.getElementById(
'x').value,
document.getElementById('y').value));">
<input type="text" id="x" value="">
<input type="text" id="y" value="">
<input type="submit" value="Submit">
</form>
</body>
</html>
Write a program that will help an elementary-school
student learn multiplication. Use Math.random to
produce two positive one-digit integers. It should then
display a question such as How much is 6 times 7?
The student then types the answer into a text field.
Your program checks the student’s answer. If it’s
correct, display the string "Very good!" and generate a
new question. If the answer is wrong, display the
string "No. Please try again." and let the student try
the same question again repeatedly until he or she
finally gets it right. A separate function should be used
to generate each new question.
This function should be called once when the script
begins execution and each time the useranswers the
question correctly.
<html>
<head>
<script type="text/javascript" >
var number1;
var number2;
function checkResult(product){
if (product == number1 * number2){
document.getElementById("product").value = "";
document.getElementById("result").innerHTML = "Very
good!";
doCalculation(); }
else
document.getElementById("result").innerHTML =
"No. Please try again"; }

function doCalculation(){
number1 = Math.floor((Math.random()*10));
number2 = Math.floor((Math.random()*10));
document.getElementById("question").innerHTML =
"How much is " + number1 + " times " + number2 +
"</b>?";
}
</script> </head>
<body onload="doCalculation();">
<label id="question"> </label><br/>
<input type="text" id="product">
<button
onclick="checkResult(document.getElementById('produ
ct').value);">
Check</button>
<label id="result"> </label>
</body></html>
Write a script that plays a “guess the number” game as
follows: Your program chooses the number to be
guessed by selecting a random integer in the range 1
to 1000. The script displays the prompt Guess a
number between 1 and 1000 next to a text field. The
player types a first guess into the text field and clicks a
button to submit the guess to the script. If the player's
guess is incorrect, your program should display Too
high. Try again. or Too low. Try again. to help the
player “zero in” on the correct answer and should clear
the text field so the user can enter the next guess.
When the user enters the correct answer, display
Congratulations. You guessed the number! and clear
the text field so the user can play again. [Note: The
guessing technique employed in this problem is similar
to a binary search, which we discuss in Chapter 10,
JavaScript: Arrays.]
-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var numri=gjenero();
function gjenero(){
return Math.floor(1000*Math.random())+1;
}

function kontrollo(){
pergjigja=parseInt(document.getElementById("pergjigja
").value);
if (numri<pergjigja){
alert("Too low!");
document.getElementById("pergjigja").value="";
}
else if (numri>pergjigja){
alert("Too high!");
document.getElementById("pergjigja").value="";
}
else {
alert("Congratulations.Continue the game with another
number!"); gjenero(); } }
</script> </head>
<body>
<input type="text" id="pergjigja" >
<button onclick="kontrollo();">Check</button>

</body>
</html>

You might also like