Introduction
In this lab, we will explore the concept of converting angles from radians to degrees in JavaScript. You will learn how to use the radian to degree formula and the built-in Math.PI constant to convert angles. Through practical exercises, you will gain hands-on experience with this conversion process and enhance your understanding of trigonometry in JavaScript.
Converting Radians to Degrees
To convert an angle from radians to degrees, follow these steps:
- Open the Terminal/SSH and type
nodeto start practicing coding. - Use the following formula:
degrees = radians * (180 / Math.PI) - Replace
radiansin the formula with the value you want to convert. - The result will be in degrees.
Here's an example:
const radsToDegrees = (rad) => (rad * 180.0) / Math.PI;
radsToDegrees(Math.PI / 2); // 90
This will convert π/2 radians to 90 degrees.
Summary
Congratulations! You have completed the Radians to Degrees lab. You can practice more labs in LabEx to improve your skills.