mh108
1/9/2019 - 1:48 AM

areaOfCircle.js

areaOfCircle-- a value-returning function that accepts one argument.

// jshint esversion: 6

//define the function

function areaOfCircle(radius){
   return Math.PI * radius ** 2;
}

//test the function

//declare variables
let radius1, radius2, area1, area2;

//assign inputs
radius1 = 1;
radius2 = 5;

//call the function
area1 = areaOfCircle(radius1);  //unit circle makes a good test
area2 = areaOfCircle(radius2);

//output the results
console.log("area1 = " + area1 + " area2 = " + area2); 
alert("area1 = " + area1 + " area2 = " + area2);