Cập nhật bài tập html - javascript trên lớp

Thảo luận trong 'Java/Java Script' bắt đầu bởi hongoctrien, 6 Tháng mười một 2011.

  1. Offline

    hongoctrien

    • Friends

    Số bài viết:
    2.449
    Đã được thích:
    2.464
    Điểm thành tích:
    2.431
    Các bạn copy - dán và save, sau đó chạy thử

    Mã:
    <!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>
    - 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)



    Cập nhật:
    Function Bảng cửu chương:

    Mã:
    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>")
    }
  2. Offline

    hongoctrien

    • Friends

    Số bài viết:
    2.449
    Đã được thích:
    2.464
    Điểm thành tích:
    2.431
    Hàm kiểm tra tính hợp lệ của ngày tháng (minh họa)

    Mã:
    <!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>
    
    interpolChIpKut3 thích bài này.
  3. Offline

    tangvanbinh

    • Đội cứu hộ máy tính

    Số bài viết:
    449
    Đã được thích:
    197
    Điểm thành tích:
    140
    cập nhật thêm
    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 đó
    Mã:
    <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);
    			}
    		
    }
    

    Code tính tuổi
    Mã:
    <script>
    n=eval(prompt("nhap nam sinh"));
    a=new Date();
    a=a.getFullYear();
    tuoi=a-n;
    alert("So tuoi:"+" "+tuoi);
    </script>

Chia sẻ trang này

Advertising: Linux system admin | nukeviet | nukeviet 4 | Upload ảnh miễn phí