# JavaScript: Convert radians to degrees

## JavaScript Math: Exercise-34 with Solution

Write a JavaScript function to convert radians to degrees.

45

Sample Solution-1:

JavaScript Code:

``````// Define a function named radians_to_degrees that converts radians to degrees.
{
// Store the value of pi.
var pi = Math.PI;
// Multiply radians by 180 divided by pi to convert to degrees.
}

// Output the result of converting approximately 0.785 radians to degrees to the console.
```
```

Output:

```45
```

Visual Presentation:

Flowchart:

Sample Solution-2:

JavaScript Code:

``````// Define a function named radians_to_degrees that converts radians to degrees using an arrow function.
// Output the result of converting pi/2 radians to degrees to the console.
// Output the result of converting approximately 0.785 radians to degrees to the console.
```
```

Output:

```90
45
```

Live Demo:

See the Pen javascript-math-exercise-34 by w3resource (@w3resource) on CodePen.

Improve this sample solution and post your code through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿