Professional Documents
Culture Documents
<!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>
<!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>
<!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>
<!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;
<!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;
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>
<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>