Function bảng cửu chương trong javascript

Function bảng cửu chương trong javascript

Function Bảng cửu chương

function bangcuuchuong()
{
document.write("<table border=1 width=100%>")
    for(i=1;i<=9;i++)   
    {
	document.write("<tr>")
    for(n=2;n<=9;n++)   
    document.write("<td>" +n + "x" + i +"="+ (n*i));
    document.write("</td>");
	document.write("</tr>")
    }
document.write("</tr></table>")
}

Code tính tuổi

<script>
n=eval(prompt("nhap nam sinh"));
a=new Date();
a=a.getFullYear();
tuoi=a-n;
alert("So tuoi:"+" "+tuoi);
</script>

Bảng cửu chương từ 2 đến 9 khi nhập vào số nào thì xuất bảng cửu chương đó

<html>
n=prompt("Nhap");
if(n==2)
{document.write("<font color=red><b>BANG CUU CHUONG 2");
document.write("<font color=blue>");
	
			for(j=1;j<=9;j++)
			{
			
			document.write("<br>",j," x 2 = ",+2*j);
			}
		
}
if(n==3)
{document.write("<font color=red><b>BẢNG CỬU CHƯƠNG 3");
 document.write("<font color=blue>");
	
			for(j=1;j<=9;j++)
			{
			
			document.write("<br>"," 3 x ",j,"=",+3*j);
			}
		
}
if(n==4)
{document.write("<font color=red><b>BANG CUU CHUONG 4");
 document.write("<font color=blue>");
			for(j=1;j<=9;j++)
			{
			
			document.write("<br>",j," x 4 = ",+4*j);
			}
		
}
if(n==5)
{document.write("<font color=red><b>BANG CUU CHUONG 5");
 document.write("<font color=blue>");
			for(j=1;j<=9;j++)
			{
			
			document.write("<br>",j," x 5 = ",+5*j);
			}
		
}
else
if(n==6)
{document.write("<font color=red><b>BANG CUU CHUONG 6");
 document.write("<font color=blue>");
			for(j=1;j<=9;j++)
			{
			
			document.write("<br>",j," x 6 = ",+6*j);
			}
		
}
if(n==7)
{document.write("<font color=red><b>BANG CUU CHUONG 7");
 document.write("<font color=blue>");
			for(j=1;j<=9;j++)
			{
			
			document.write("<br>",j," x 7 = ",+7*j);
			}
		
}
if(n==8)
{document.write("<font color=red><b>BANG CUU CHUONG 8");
			for(j=1;j<=9;j++)
			{
			
			document.write("<br>",j," x 8 = ",+8*j);
			}
		
}
if(n==9)
{document.write("<font color=red><b>BANG CUU CHUONG 9</font>");
document.write("<font color=blue>");
			for(j=1;j<=9;j++)
			{
			
			document.write("<br>",j," x 9 = ",9*j);
			}
		
}

Hàm kiểm tra tính hợp lệ của ngày tháng (minh họa)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function kt()
{
	a=eval(f1.date.value);
	b=eval(f1.month.value);
	c=eval(f1.year.value);
	var now=new Date();
	var d=now.getFullYear();
	if(a.length==0 || b.length==0 || c.length==0)
		alert("Khong duoc bo trong");
	if(isNaN(a) || isNaN(b) || isNaN(c))
		alert("Khong duoc nhap chu");
	if(a<1 || a>31)
		alert("Ngay khong hop le");
	if(b<1 || b>12)
		alert("Thang khong hop le");
	else
		alert(d-c + " tuoi");
}
</script>
</head>

<body>
<form action="" method="post" name="f1">
	Ngày <input type="text" name="date" maxlength="5"/>
   	Tháng <input type="text" name="month" maxlength="5"/>
	Năm <input type="text" name="year" maxlength="5"/>
    <input type="submit" value="OK" onclick="kt()"/>
</form>
</body>
</html>

- Kiểm tra một số có chia hết cho một số

- Tìm số lớn nhất trong 3 số nguyên

- Tính tổng, hiệu, tích, thương của 2 số nguyên

- Giải phương trình bậc 2

- Tính tích các số lẽ

- Lũy thừa

- In tam giác hình sao (2 dạng)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script>
function chiahet()
{
	a=prompt("Nhap  so thu 1: ");
	b=prompt("Nhap  so thu 2: ");
	if(a%b==0)
		alert("So 1 chia het cho so 2");
	else
		alert("So 1 khong chia het cho so 2");
}

function maxi()
{
	a=eval(prompt("Nhap  so thu 1: "));
	b=eval(prompt("Nhap  so thu 2: "));
	c=eval(prompt("Nhap  so thu 2: "));
	max=a;
	if (b>max)
		max=b;
	if (c>max)
		max=c;
	alert("So lon nhat: " +max);
}

function vd()
{
	a=eval(prompt("Nhap  so thu 1: "));
	b=eval(prompt("Nhap  so thu 2: "));
	tong=a+b;
	hieu=a-b;
	tich=a*b;
	thuong=a/b;
	alert("Tong: " +tong);
	alert("hieu: " +hieu);
	alert("Tich: " +tich);
	alert("Thuong: " +thuong);
}

function ptbac2()
{
	a=eval(prompt("a= "));
	b=eval(prompt("b= "));
	c=eval(prompt("c= "));
	denta=b*b-4*a*c;
	if(denta==0)
		alert("Phuong trinh co nghiem kep " + (-b/2*a));
	if(denta>0)
		alert("Phuong trinh co 2 nghiem phan biet, x1= " + Math.round((-b-Math.sqrt(denta)/2*a),2) + "        x2= " + Math.round((-b+Math.sqrt(denta)/2*a),2));
	else
		alert("Phuong trinh vo nghiem");
}

function tichsole()
{
	tich=1;
	n=eval(prompt("So cuoi cung: "));
	document.write("DS so le: ");
	for(i=1;i<=n;i++)
	{
		if(i%2!=0)
		{
		tich=tich*i;
		document.write(" "+i+" ");
		}
	}
	alert("Tich: " +tich);
}

function luythua()
{
	x=eval(prompt("x= "));
	n=eval(prompt("n= "));
	alert("Ket qua " +(Math.pow(x,n)));
}

function sao()
{
	n=eval(prompt("So hang= "));
  for (i=0; i<n; i++)
  {
    for (j=n-1; j>i; j--)
      document.write("&nbsp;&nbsp;");
    for (j=0; j<i*2+1; j++)
      document.write("*");
    document.write("<br>");
  }
}

function sao1()
{
	n=eval(prompt("So hang= "));
	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n*2-1;j++)
			if((j==n-1-i)||(j==n-1+i))
				document.write("*");
			else
				document.write("&nbsp;&nbsp;");
				document.write("<br>");
	}
	for(j=0;j<2*n-1;j++)
	document.write("*");
}

  

</script>
<body>
</body>
<input type="button" value="Kiểm tra chia hết" onclick="chiahet()"  /><br />
<input type="button" value="Tìm số lớn nhất" onclick="maxi()"  /><br />
<input type="button" value="Star" onclick="vd()"  /><br />
<input type="button" value="Giải pt bậc 2" onclick="ptbac2()"  /><br />
<input type="button" value="Tích số lẻ" onclick="tichsole()"  /><br />
<input type="button" value="Lỹ thừa" onclick="luythua()"  /><br />
<input type="button" value="Sao" onclick="sao()"  /><br />
<input type="button" value="Sao1" onclick="sao1()"  /><br />
</html>
Bạn thấy bài viết này như thế nào?: 
Average: 5.9 (8 votes)
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Elon Musk lên tiếng phủ nhận chuyện qua đêm với hai mỹ nhân

Elon Musk lên tiếng phủ nhận chuyện qua đêm với hai mỹ nhân

Tỉ phú Elon Musk lên tiếng trước nghi án sex tập thể với Amber Heard và Cara Delevingne

Người Việt online gấp đôi thời gian xem TV

Người Việt online gấp đôi thời gian xem TV

81% người Việt tham gia khảo sát của Google truy cập Internet thường xuyên và thời gian dành cho online mỗi ngày là 5,6 giờ.

Drupal 8 và Backdrop CMS

So sánh 10 điểm khác biệt giữa Drupal 8 và Backdrop CMS

Many of you reading this will be familiar with Backdrop, but for those of you who haven't heard of the project,

Công ty diệt chuột T&C

 

Diet con trung