Hướng dẫn html code for area of rectangle - mã html cho diện tích hình chữ nhật

Tôi phải tạo một hàm để tính toán khu vực, chu vi và âm lượng của hình chữ nhật, nhắc người dùng vào chiều cao, chiều rộng và chiều dài và ghi ra các đầu vào và đầu ra bằng document.writeln [].

Những gì tôi đã thử:

var length = prompt ["Nhập toàn bộ số cho chiều dài của hình chữ nhật của bạn."]; Var Width = Prompt ["Nhập toàn bộ số cho chiều rộng của hình chữ nhật của bạn."];
var width = prompt ["Enter a whole number for the width of your rectangle."];

khu vực hàm [chiều dài, chiều rộng] {return lwm * chiều rộng; }
return length * width;
}

Console.log [khu vực hình chữ nhật của bạn là " + khu vực];

Giải pháp 4

thử


    
        var length = prompt["Enter a whole number for the length of your rectangle."];
        var width = prompt["Enter a whole number for the width of your rectangle."];
        function area[length, width] {
            return length * width;
        }
        function perimeter[length, width] {
            return 2*[ length + width];
        }
        
        document.writeln['The area of your rectangle is ' + area[length, width]];         
        document.writeln['The perimeter of your rectangle is ' + perimeter[length, width]];

             
    


    

Giải pháp 1

Xin vui lòng xem





Click the button keyin inputs .

Try it






function myFunction[] {
  
var length = prompt["Enter a whole number for the length of your rectangle."];
var width = prompt ["Enter a whole number for the width of your rectangle."];
var depth= prompt ["Enter a whole number for the depth of your rectangle prism"];

   
var perimeter = [2 * length ] + [2 * width ];
var area= length * width ;
var volume= length * width * depth;

 document.getElementById["a"].innerHTML =
        "Area of rectangle:"  + area;
 document.getElementById["p"].innerHTML =
        "perimeter of rectangle:"  + perimeter ;
 document.getElementById["v"].innerHTML =
        "volume of rectangle prism:"  + volume;
}



Cập nhật 18-tháng 10-16 10:49 sáng 18-Oct-16 10:49am

Giải pháp 2

Trong JavaScript, mọi thứ thực thi trừ khi chúng bị ràng buộc với bối cảnh hoặc là một hàm. Các chức năng cần được gọi trước khi chúng có thể thực thi. Chỉ cần thay đổi dòng sau,

console.log["The area of your rectangle is " + area[length, width]]; // 

Chủ Đề