14.6 Homework Assignment
Task:
Example Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shape Area and Perimeter Calculations</title>
</head>
<body>
<h1>Check the Console for Shape Calculations</h1>
<script>
// Function to calculate the area and perimeter of a rectangle
function rectangleArea(length, width) {
return length * width;
}
function rectanglePerimeter(length, width) {
return 2 * (length + width);
}
// Function to calculate the area and circumference of a circle
function circleArea(radius) {
return Math.PI * radius * radius;
}
function circleCircumference(radius) {
return 2 * Math.PI * radius;
}
// Function to calculate the area and perimeter of a triangle
function triangleArea(base, height) {
return 0.5 * base * height;
}
function trianglePerimeter(side1, side2, side3) {
return side1 + side2 + side3;
}
// Example Calculations
let length = 10, width = 5, radius = 7, base = 6, height = 8, side1 = 5, side2 = 6, side3 = 7;
// Rectangle
console.log("Rectangle Area: " + rectangleArea(length, width)); // Outputs: Rectangle Area: 50
console.log("Rectangle Perimeter: " + rectanglePerimeter(length, width)); // Outputs: Rectangle Perimeter: 30
// Circle
console.log("Circle Area: " + circleArea(radius).toFixed(2)); // Outputs: Circle Area: 153.94
console.log("Circle Circumference: " + circleCircumference(radius).toFixed(2)); // Outputs: Circle Circumference: 43.98
// Triangle
console.log("Triangle Area: " + triangleArea(base, height)); // Outputs: Triangle Area: 24
console.log("Triangle Perimeter: " + trianglePerimeter(side1, side2, side3)); // Outputs: Triangle Perimeter: 18
</script>
</body>
</html>Instructions:
Challenge:
Homework Submission:
Expected Outcome:
Last updated